change the location of a group of buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prathap
    New Member
    • Nov 2011
    • 37

    change the location of a group of buttons

    I have 25 buttons in a form.
    Here is the code below that i have used to change the location of One button at run time.
    Code:
    Public Class table
        Private dragging As Boolean
        Private beginX, beginY As Integer
        Private Sub Button1_mousedown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
            dragging = True
            beginX = e.X
            beginY = e.Y
        End Sub
        Private Sub Button1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseMove
            If dragging = True Then
                Button1.Location = New Point(Button1.Location.X + e.X - beginX, Button1.Location.Y + e.Y - beginY)
                Me.Refresh()
            End If
        End Sub
        Private Sub Button1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseUp
            dragging = False
        End Sub
    End Class
    Now i want to Change the location of remaining 24 buttons.So, should i write this code for all those buttons or is there any easier way to do the same?
    Could someone please help?
  • IronRazer
    New Member
    • Jan 2013
    • 83

    #2
    Hello Prathap,
    Are the buttons going to be placed randomly or do you want to keep them in the same order and just move them all? If you want to keep them in the same order then you could try placing them all onto a Panel and use your code to move the whole Panel. If you want to move them around one by one and place them in a random spot then I think you will need to write this for each button.

    Comment

    Working...