what is the code to move a command button to a different form when the mouse is draged over it?
Printable View
what is the code to move a command button to a different form when the mouse is draged over it?
you can't just move it.
you can hide it on the form and show it on the form you want to move it from.
You can do this in Delphi because it gives you read/write access to the Parent <grin>
However, you can simulate this by creating the Command Button at run-time using the
syntax - change "ButtonName" to something meaningful - you can then destroy this withCode:Controls.Add("VB.CommandButton", "ButtonName")
if you read all the properties into a UDT and create an abstracted event it will appear as if you have 'moved' the button.Code:Controls.Remove("ButtonName")
Best of all create a new Class of Button then you can set the defaults and not worry about having to replicate them each time.
Cheers,
Paul.
Actually, you CAN just move it. :rolleyes:
This code goes in Form1:
Code:Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Sub Command1_Click()
' Whatever you want the button to do, goes here.
' It will execute it regardless of the form that it's on.
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If GetParent(Command1.hWnd) = Form1.hWnd Then Call SetParent(Command1.hWnd, Form2.hWnd)
End Sub
Private Sub Form_Load()
Call Form2.Show
End Sub
I knew there must be an API to do that 'cos the Delphi class is just a wrapper.
I tried looking it up on Microsoft's site but as usual got a load of unrelated cr*p.
1-0 to Yonatan.
Well played that man, still like my class tho' <grin>
Paul.
P.S. Mind you I have tried the code and it has some v. odd effects on Focus...
[Edited by paulw on 10-31-2000 at 11:32 AM]