|
-
Oct 30th, 2000, 08:57 PM
#1
Thread Starter
New Member
what is the code to move a command button to a different form when the mouse is draged over it?
-
Oct 31st, 2000, 09:58 AM
#2
Addicted Member
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.
-
Oct 31st, 2000, 10:37 AM
#3
Fanatic Member
Move a control
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
Code:
Controls.Add("VB.CommandButton", "ButtonName")
syntax - change "ButtonName" to something meaningful - you can then destroy this with
Code:
Controls.Remove("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.
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.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Oct 31st, 2000, 10:48 AM
#4
Guru
Time to surprise you all!
Actually, you CAN just move it. 
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
-
Oct 31st, 2000, 11:24 AM
#5
Fanatic Member
Beat me to it
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]
Not nearly so tired now...
Haven't been around much so be gentle...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|