Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Moving a form using a button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Moving a form using a button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Moving a form using a button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Moving a form using a button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Moving a form using a button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Moving a form using a button

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,344
Default Moving a form using a button

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving within a form Cindi Excel Programming 9 June 13th 08 01:58 PM
Moving around an User Form Fredriksson via OfficeKB.com Excel Programming 2 March 13th 07 10:29 PM
How to pick one or more items out of a list, moving to new list, moving up or down. (form) Subteam Excel Discussion (Misc queries) 3 February 17th 06 04:13 AM
button moving Shawn Excel Discussion (Misc queries) 3 August 30th 05 04:09 PM
Moving objects on a form Steven K Excel Programming 1 August 23rd 04 06:13 PM


All times are GMT +1. The time now is 12:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"