Moving multiple controls simultaneously

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U2FyYWggTWFycmlvdHQ=?=

    Moving multiple controls simultaneously

    Hi all,

    I hope this is the correct forum for my VB.NET forms based question.

    I have written an application which uses my own user controls which the user
    can position dynamically on a form.
    The user control has several standard controls on it (labels/comboboxes etc)
    but there is space at the top allowing the user to click on the control
    itself.
    The code I use at the moment to allow the user to move the control is fairly
    simple:


    Private Sub DataSource_Mous eDown(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs)
    If State = WAITING Then
    State = DRAGGING
    Pic_X = e.X 'Pic_X and Pic_Y are declared on the form
    Pic_Y = e.Y
    End If

    End Sub
    Private Sub DataSource_Mous eMove(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs)
    If State = DRAGGING Then
    If TypeOf sender Is ctl_Datasource Then
    Dim mox As Integer
    Dim moy As Integer

    mox = e.X - Pic_X
    moy = e.Y - Pic_Y

    sender.Top = sender.top + moy
    sender.Left = sender.Left + mox
    End If
    End If
    End Sub

    Private Sub DataSource_Mous eUp(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs)
    State = WAITING
    End Sub

    The controls (of which there can be over 20 on the form at any one time) are
    generated dynamically when the form loads and moved into position based on
    their last known position, which was stored in a database when the form was
    last closed.

    My main problem is that I would like the user to be able to 'drag select'
    several controls and move them simultaneously. Something similar to
    selecting and dragging several things around on the desktop together.This
    would make organising the form so much easier!

    Can anyone give me any pointers?

    TIA

    Sarah
  • Lloyd Sheen

    #2
    Re: Moving multiple controls simultaneously


    "Sarah Marriott" <SarahMarriott@ discussions.mic rosoft.comwrote in message
    news:765945E0-E3CC-4A01-8699-EE8F668CBA69@mi crosoft.com...
    Hi all,
    >
    I hope this is the correct forum for my VB.NET forms based question.
    >
    I have written an application which uses my own user controls which the
    user
    can position dynamically on a form.
    The user control has several standard controls on it (labels/comboboxes
    etc)
    but there is space at the top allowing the user to click on the control
    itself.
    The code I use at the moment to allow the user to move the control is
    fairly
    simple:
    >
    >
    Private Sub DataSource_Mous eDown(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs)
    If State = WAITING Then
    State = DRAGGING
    Pic_X = e.X 'Pic_X and Pic_Y are declared on the form
    Pic_Y = e.Y
    End If
    >
    End Sub
    Private Sub DataSource_Mous eMove(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs)
    If State = DRAGGING Then
    If TypeOf sender Is ctl_Datasource Then
    Dim mox As Integer
    Dim moy As Integer
    >
    mox = e.X - Pic_X
    moy = e.Y - Pic_Y
    >
    sender.Top = sender.top + moy
    sender.Left = sender.Left + mox
    End If
    End If
    End Sub
    >
    Private Sub DataSource_Mous eUp(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs)
    State = WAITING
    End Sub
    >
    The controls (of which there can be over 20 on the form at any one time)
    are
    generated dynamically when the form loads and moved into position based on
    their last known position, which was stored in a database when the form
    was
    last closed.
    >
    My main problem is that I would like the user to be able to 'drag select'
    several controls and move them simultaneously. Something similar to
    selecting and dragging several things around on the desktop together.This
    would make organising the form so much easier!
    >
    Can anyone give me any pointers?
    >
    TIA
    >
    Sarah
    Sarah,

    You would first need a method to select the controls to move. This
    could be CTL-Click etc. Then each control which was selected would be added
    to a list of controls. Then in the DataSource_Mous eMove method you would do
    a loop thru the controls and move each one using top and left.

    LS

    Comment

    Working...