Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi all bit of a query if anyone can help
i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You didn't post any code showing how you removed the border or where your
"border image" is, so I'll just show you the technique on a normal UserForm and you can see if you can adapt it to your actual situation. Note that the following code uses the UserForm's Caption... even though you have removed the TitleBar, which I guess you did with API code, you can still assign a Caption value to the UserForm so the FindWindow API function call below has something to work with. Anyway, insert a new UserForm (you can put controls on it or not as you wish) and copy/paste the following code into its code window. As written, the code requires the user to hold the Shift key down and left click on an unused area of the UserForm and drag it around. I thought requiring the Shift key made sense for this functionality (Shift key.. shift the form around the screen), but if you want the user to only have to left click an unused area of the UserForm and drag without the Shift key, remove the And Shift = 1 part of the If..Then statement in the MouseDown event procedure. '*************** START OF CODE *************** Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_Initialize() hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi all bit of a query if anyone can help i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
hi rick heres my code with yours mashed in
Private Declare Function FindWindow& Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) Private Declare Function SetWindowLong& Lib "user32" Alias _ "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal wNewWord&) Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd&) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() Dim hWnd& hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub it removes the title and border (only for userform1) but your added code does not work. i tried holding the shift key down but found i couldnt move the form. can you show me how to not have to hold the shift key but to simply have to click image1 and keep the finger on the mouse button to drag it anywhere thanks again rivers "Rick Rothstein" wrote: You didn't post any code showing how you removed the border or where your "border image" is, so I'll just show you the technique on a normal UserForm and you can see if you can adapt it to your actual situation. Note that the following code uses the UserForm's Caption... even though you have removed the TitleBar, which I guess you did with API code, you can still assign a Caption value to the UserForm so the FindWindow API function call below has something to work with. Anyway, insert a new UserForm (you can put controls on it or not as you wish) and copy/paste the following code into its code window. As written, the code requires the user to hold the Shift key down and left click on an unused area of the UserForm and drag it around. I thought requiring the Shift key made sense for this functionality (Shift key.. shift the form around the screen), but if you want the user to only have to left click an unused area of the UserForm and drag without the Shift key, remove the And Shift = 1 part of the If..Then statement in the MouseDown event procedure. '*************** START OF CODE *************** Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_Initialize() hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi all bit of a query if anyone can help i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
First off, I could swear when I first developed my code (it was a few months
ago if I remember correctly), I thought I tried vbNullString (which is the relatively standard thing to do) as the first argument to FindWindows and that it didn't work, which is why I eventually settled on using "ThunderDFrame"... but apparently I was wrong because vbNullString seems to work fine, so I'm glad you brought this question up as I can now go back to doing this the standard way. Okay, the main problem in why your code isn't working is because you declared the hWnd variable local to the Initialize event whereas my code needs it declared in the (General)(Declarations) section of the UserForm's code window (it is needed in two separate event procedures, so it must be locally global at a minimum... your local declaration overrode my locally global declaration). Try the following code which should work... '*************** START OF CODE *************** Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function SetWindowLong& Lib "user32" _ Alias "SetWindowLongA" _ (ByVal hWnd As Long, _ ByVal nIndex As Long, _ ByVal wNewWord As Long) Private Declare Function DrawMenuBar& Lib "user32" _ (ByVal hWnd As Long) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi rick heres my code with yours mashed in Private Declare Function FindWindow& Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) Private Declare Function SetWindowLong& Lib "user32" Alias _ "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal wNewWord&) Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd&) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() Dim hWnd& hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub it removes the title and border (only for userform1) but your added code does not work. i tried holding the shift key down but found i couldnt move the form. can you show me how to not have to hold the shift key but to simply have to click image1 and keep the finger on the mouse button to drag it anywhere thanks again rivers "Rick Rothstein" wrote: You didn't post any code showing how you removed the border or where your "border image" is, so I'll just show you the technique on a normal UserForm and you can see if you can adapt it to your actual situation. Note that the following code uses the UserForm's Caption... even though you have removed the TitleBar, which I guess you did with API code, you can still assign a Caption value to the UserForm so the FindWindow API function call below has something to work with. Anyway, insert a new UserForm (you can put controls on it or not as you wish) and copy/paste the following code into its code window. As written, the code requires the user to hold the Shift key down and left click on an unused area of the UserForm and drag it around. I thought requiring the Shift key made sense for this functionality (Shift key.. shift the form around the screen), but if you want the user to only have to left click an unused area of the UserForm and drag without the Shift key, remove the And Shift = 1 part of the If..Then statement in the MouseDown event procedure. '*************** START OF CODE *************** Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_Initialize() hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi all bit of a query if anyone can help i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
rick it still wont work i think im doing something wrong
i inserted the code exactly as described and only removed the shift button option. but none of my buttons on my mouse are moving the form. (just to let you know my form is entily covered by a picture does this matter? ps thanks for you help so far "Rick Rothstein" wrote: First off, I could swear when I first developed my code (it was a few months ago if I remember correctly), I thought I tried vbNullString (which is the relatively standard thing to do) as the first argument to FindWindows and that it didn't work, which is why I eventually settled on using "ThunderDFrame"... but apparently I was wrong because vbNullString seems to work fine, so I'm glad you brought this question up as I can now go back to doing this the standard way. Okay, the main problem in why your code isn't working is because you declared the hWnd variable local to the Initialize event whereas my code needs it declared in the (General)(Declarations) section of the UserForm's code window (it is needed in two separate event procedures, so it must be locally global at a minimum... your local declaration overrode my locally global declaration). Try the following code which should work... '*************** START OF CODE *************** Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function SetWindowLong& Lib "user32" _ Alias "SetWindowLongA" _ (ByVal hWnd As Long, _ ByVal nIndex As Long, _ ByVal wNewWord As Long) Private Declare Function DrawMenuBar& Lib "user32" _ (ByVal hWnd As Long) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi rick heres my code with yours mashed in Private Declare Function FindWindow& Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) Private Declare Function SetWindowLong& Lib "user32" Alias _ "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal wNewWord&) Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd&) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() Dim hWnd& hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub it removes the title and border (only for userform1) but your added code does not work. i tried holding the shift key down but found i couldnt move the form. can you show me how to not have to hold the shift key but to simply have to click image1 and keep the finger on the mouse button to drag it anywhere thanks again rivers "Rick Rothstein" wrote: You didn't post any code showing how you removed the border or where your "border image" is, so I'll just show you the technique on a normal UserForm and you can see if you can adapt it to your actual situation. Note that the following code uses the UserForm's Caption... even though you have removed the TitleBar, which I guess you did with API code, you can still assign a Caption value to the UserForm so the FindWindow API function call below has something to work with. Anyway, insert a new UserForm (you can put controls on it or not as you wish) and copy/paste the following code into its code window. As written, the code requires the user to hold the Shift key down and left click on an unused area of the UserForm and drag it around. I thought requiring the Shift key made sense for this functionality (Shift key.. shift the form around the screen), but if you want the user to only have to left click an unused area of the UserForm and drag without the Shift key, remove the And Shift = 1 part of the If..Then statement in the MouseDown event procedure. '*************** START OF CODE *************** Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_Initialize() hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi all bit of a query if anyone can help i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Scratch that previous comment rick it worked brilliantly. i changed the
userform mousedown to image1 and it worked beautifully. you are a diamond geezer. rick before you end this post can i ask another question? i have tried the remove caption and border on other user forms but find that the same code does not work i was wondering being as you nicely neatened up my code did you notice anything that would stop other userforms from working the same as userform1? "Rick Rothstein" wrote: First off, I could swear when I first developed my code (it was a few months ago if I remember correctly), I thought I tried vbNullString (which is the relatively standard thing to do) as the first argument to FindWindows and that it didn't work, which is why I eventually settled on using "ThunderDFrame"... but apparently I was wrong because vbNullString seems to work fine, so I'm glad you brought this question up as I can now go back to doing this the standard way. Okay, the main problem in why your code isn't working is because you declared the hWnd variable local to the Initialize event whereas my code needs it declared in the (General)(Declarations) section of the UserForm's code window (it is needed in two separate event procedures, so it must be locally global at a minimum... your local declaration overrode my locally global declaration). Try the following code which should work... '*************** START OF CODE *************** Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function SetWindowLong& Lib "user32" _ Alias "SetWindowLongA" _ (ByVal hWnd As Long, _ ByVal nIndex As Long, _ ByVal wNewWord As Long) Private Declare Function DrawMenuBar& Lib "user32" _ (ByVal hWnd As Long) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi rick heres my code with yours mashed in Private Declare Function FindWindow& Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) Private Declare Function SetWindowLong& Lib "user32" Alias _ "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal wNewWord&) Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd&) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() Dim hWnd& hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub it removes the title and border (only for userform1) but your added code does not work. i tried holding the shift key down but found i couldnt move the form. can you show me how to not have to hold the shift key but to simply have to click image1 and keep the finger on the mouse button to drag it anywhere thanks again rivers "Rick Rothstein" wrote: You didn't post any code showing how you removed the border or where your "border image" is, so I'll just show you the technique on a normal UserForm and you can see if you can adapt it to your actual situation. Note that the following code uses the UserForm's Caption... even though you have removed the TitleBar, which I guess you did with API code, you can still assign a Caption value to the UserForm so the FindWindow API function call below has something to work with. Anyway, insert a new UserForm (you can put controls on it or not as you wish) and copy/paste the following code into its code window. As written, the code requires the user to hold the Shift key down and left click on an unused area of the UserForm and drag it around. I thought requiring the Shift key made sense for this functionality (Shift key.. shift the form around the screen), but if you want the user to only have to left click an unused area of the UserForm and drag without the Shift key, remove the And Shift = 1 part of the If..Then statement in the MouseDown event procedure. '*************** START OF CODE *************** Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_Initialize() hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi all bit of a query if anyone can help i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
You mentioned putting buttons for the user on the form. If you choose that method then your code of course would be very simple, one line each for four buttons: Me.Left = Me.Left + 10 Me.Left = Me.Left - 10 Me.Top = Me.Top + 10 Me.Top = Me.Top - 10 When you choose to make a paradym shift there is always the danger you will loose the user. -- Thanks, Shane Devenshire "Rivers" wrote: hi rick heres my code with yours mashed in Private Declare Function FindWindow& Lib "user32" Alias _ "FindWindowA" (ByVal lpClassName$, ByVal lpWindowName$) Private Declare Function SetWindowLong& Lib "user32" Alias _ "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal wNewWord&) Private Declare Function DrawMenuBar& Lib "user32" (ByVal hWnd&) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub Sub UserForm_Initialize() Dim hWnd& hWnd = FindWindow(vbNullString, Me.Caption) SetWindowLong hWnd, -16, &H84080080 ' remove caption DrawMenuBar hWnd SetWindowLong hWnd, -20, &H40000 ' remove borders Call ListOpenWorkbooks Listworksheets Workbooks("Navigator").Sheets("Tables").Calculate MultiPage1.Value = 0 hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub it removes the title and border (only for userform1) but your added code does not work. i tried holding the shift key down but found i couldnt move the form. can you show me how to not have to hold the shift key but to simply have to click image1 and keep the finger on the mouse button to drag it anywhere thanks again rivers "Rick Rothstein" wrote: You didn't post any code showing how you removed the border or where your "border image" is, so I'll just show you the technique on a normal UserForm and you can see if you can adapt it to your actual situation. Note that the following code uses the UserForm's Caption... even though you have removed the TitleBar, which I guess you did with API code, you can still assign a Caption value to the UserForm so the FindWindow API function call below has something to work with. Anyway, insert a new UserForm (you can put controls on it or not as you wish) and copy/paste the following code into its code window. As written, the code requires the user to hold the Shift key down and left click on an unused area of the UserForm and drag it around. I thought requiring the Shift key made sense for this functionality (Shift key.. shift the form around the screen), but if you want the user to only have to left click an unused area of the UserForm and drag without the Shift key, remove the And Shift = 1 part of the If..Then statement in the MouseDown event procedure. '*************** START OF CODE *************** Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hWnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function ReleaseCapture Lib "user32" () As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Const HTCAPTION = 2 Dim hWnd As Long Private Sub UserForm_Initialize() hWnd = FindWindow("ThunderDFrame", Me.Caption) End Sub Private Sub UserForm_MouseDown(ByVal Button As Integer, _ ByVal Shift As Integer, _ ByVal X As Single, ByVal Y As Single) If Button = xlPrimaryButton And Shift = 1 Then Call ReleaseCapture Call SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&) End If End Sub '*************** END OF CODE *************** -- Rick (MVP - Excel) "Rivers" wrote in message ... hi all bit of a query if anyone can help i have removed my border to my form and the caption and the x button but this locks my form to the position of where it loads and this is dreadfull can anyone help me with some code that allows the user to grab the border image that i have and allow the user to move the form. or even move the form when they click on a button eithers good. thanks for any help given rivers |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Moving within a form | Excel Programming | |||
Moving around an User Form | Excel Programming | |||
How to pick one or more items out of a list, moving to new list, moving up or down. (form) | Excel Discussion (Misc queries) | |||
button moving | Excel Discussion (Misc queries) | |||
Moving objects on a form | Excel Programming |