Results 1 to 7 of 7

Thread: Make a label control the window

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    51

    Angry Make a label control the window

    Does anyone know how to make a label on a form act as the control to move the window around...That is, when the left mouse button is down on the label, you can drag the form around the screen.

    Thanks.
    "We can't solve problems by using the same kind of thinking we used when we created them."
    -Albert Einstein

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    As the label doesn't have the Hwnd property. i am afraid it is not possible.. yes u can do one thing
    Set the borderstyle property of Textbox to None.. Appearance to Flat and color to ButtonFace..(Gray) then you can use SendMessage to do what you want.. tell me if this textbox thingy is acceptable

  3. #3
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Don't forget to set the mousepointer property to Arrow (1)

    VB Code:
    1. 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
    2.  
    3. Private Declare Function ReleaseCapture Lib "user32" () As Long
    4.  
    5. Private Const WM_NCLBUTTONDOWN = &HA1
    6.  
    7. Private Const HTCAPTION = 2
    8.  
    9.  
    10. Private Sub Form_Load()
    11.  
    12. End Sub
    13.  
    14. Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    15. If Button = vbLeftButton Then
    16.     ReleaseCapture
    17.     SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0
    18. End If
    19. End Sub

  4. #4

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    51

    Thumbs up Hey, thanks...also..

    Thanks for that one.
    It works like a charm, but do you know how to remove the cursor that blinks with it?, because it's still flashing.

    Thanks.
    "We can't solve problems by using the same kind of thinking we used when we created them."
    -Albert Einstein

  5. #5
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    Here's another way to do it without using the API
    VB Code:
    1. Option Explicit
    2.  
    3. Private MbMov As Boolean
    4. Private PrevX As Long
    5. Private PrevY As Long
    6.  
    7. Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    8.    
    9.     MbMov = True
    10.     PrevX = X
    11.     PrevY = Y
    12.  
    13. End Sub
    14.  
    15. Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    16.  
    17.     If MbMov Then
    18.         Me.Move (Me.Left + X - PrevX), (Me.Top + Y - PrevY)
    19.     End If
    20.  
    21. End Sub
    22.  
    23. Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    24.    
    25.     MbMov = False
    26.  
    27. End Sub

  6. #6

    Thread Starter
    Member
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    51

    Thumbs up Ace

    hey thanks for those, they both worked like a charm...
    "We can't solve problems by using the same kind of thinking we used when we created them."
    -Albert Einstein

  7. #7
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: Hey, thanks...also..

    Originally posted by jontyrules
    Thanks for that one.
    It works like a charm, but do you know how to remove the cursor that blinks with it?, because it's still flashing.

    Thanks.
    I told ya can also use a picture box

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