Results 1 to 5 of 5

Thread: Dragging Labels and picture boxes

  1. #1
    Guest
    How do i drag labels and/or picture boxes across a form?

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Simply set the picturebox or label's dragmode property to "1-Automatic". Then paste the follow code onto the form:

    Code:
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Left = X
    Source.Top = Y
    End Sub
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3
    Hyperactive Member Asaf_99's Avatar
    Join Date
    Jul 2000
    Location
    Israel
    Posts
    335
    Good one, Metthew, but I think this would be better:
    Code:
    Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
    Source.Top = Y - Source.Height / 2
    Source.Left = X - Source.Width / 2
    End Sub
    Asaf Sagi

    ICQ: 61917199
    E-Mail: [email protected]

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'Picture box is the the same situtation.
    [code]
    'Allowing a form control to be movable (DRAG AND DROP)
    '...ie drag label1

    Option Explicit

    Public globalX As Integer
    Public globalY As Integer

    Private Sub Form_DragDrop(Source As Control, X As _
    Single, Y As Single)
    Label1.Move X - globalX, Y - globalY
    End Sub

    Private Sub Label1_MouseDown(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
    Label1.Drag vbBeginDrag
    globalX = X
    globalY = Y
    End Sub

    [code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Guest
    Code:
    Dim prevX As Long
    Dim prevY As Long
    
    Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        prevX = X: prevY = Y
    End Sub
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then Picture1.Move Picture1.Left + (X - prevX), Picture1.Top + (Y - prevY)
    End Sub

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