Author Topic: Moving components at runtime  (Read 920 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Moving components at runtime
« on: October 15, 2016, 09:52:42 PM »
How would I go about moving a component at runtime?  I would like to use a label as a slider and move it along a bar level control to adjust min/max  tolerance values of the bar level.  Basically I want one as "min value" and another as "max value" and be able to slide them the full length of the bar level control.  Not sure how to link the labels to the length of the bar level either.  Thanks. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Moving components at runtime
« Reply #1 on: October 15, 2016, 10:30:44 PM »
Something like this is a fairly simple way:

Code: [Select]
    Private StartX, StartY As Integer
    Private Sub Label1_MouseDown(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown
        StartX = e.X
        StartY = e.Y
    End Sub


    Private Sub Label1_MouseMove(sender As Object, e As MouseEventArgs) Handles Label1.MouseMove
        If e.Button = MouseButtons.Left Then
            Label1.Location = New Point(Label1.Location.X + e.X - StartX, Label1.Location.Y + e.Y - StartY)
        End If
    End Sub