Results 1 to 5 of 5

Thread: code

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    15

    Lightbulb

    what is the code to move a command button to a different form when the mouse is draged over it?

  2. #2
    Addicted Member ShIzO's Avatar
    Join Date
    Apr 1999
    Location
    Bartlett, IL
    Posts
    189
    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.

    www.HardFind.com -buy/sell/trade your used hardware.

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008

    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...

  4. #4
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Cool 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

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008

    Thumbs up 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
  •  



Click Here to Expand Forum to Full Width