locked
Make Form1 Buttons Move down from certain location RRS feed

  • Question

  • Hi I dont know how to exaplin this but I will try my best. I want to make a row of buttons to move down when I drop a new button into the form1. Like If i drop the button lets say between Me.location.Y=10 and Me.Location.Y=30
    I want ALL the buttons that are Bellow Me.Location.Y=30 To move down 10 Pixels...(Y += 10)  SO Each button in this Form that is UNder the Location of Y=30 to move down 10 pixels each (Y += 10)

    Like this


    Before Button is Droped

    Form1            [_][=][X]
    -----------------------------------

    [button1]
    [button2]
    [button3]
    [button4]
    [button5]
    ----------------------------------


    After Button is Droped

    Form1            [_][=][X]
    -----------------------------------

    [Button6]






    [button1]
    [button2]
    [button3]
    [button4]
    [button5]
    ----------------------------------


    I dont need the Drag and drop Codes I just want to know how I can move more than one control in the Form at once Because my buttons get Added with Add Handlers so they dont have Names I cant Just put Button1.Location= New system.drawing.Point(1,1)   Beacouse the button1 does not exist Yet when I am Making the program. Thats why I want to be able to Move Controls Down instead of a Specific Button to move I want ALL buttons that Exist on the form to move down.
    Sunday, February 17, 2008 6:20 PM

Answers

  •  Actually thinking about it, as you don't know at the start how many buttons there are going to be, you would be better off with a list.  Dim it like this:

     

    Dim Buttons As New List(Of Button)

     

    Add a new button to it like this:

     

    Dim B As New Button

    Buttons.Add(B)

     

    and move them like this:

     

    For Each Btn As Button In Buttons

    ' your code to move them here

    Next

    Sunday, February 17, 2008 7:53 PM

All replies

  • How about adding the buttons to an array as you create them.  Then all you have to do is run through the array moving all the buttons in it as required.

    Sunday, February 17, 2008 6:59 PM
  • I am a bit new to visual basic I have seen the array methods many times but I dont know how to add my buttons to this array. Or even touch the array.  Do I use the Dim Function?
    Sunday, February 17, 2008 7:03 PM
  •  Actually thinking about it, as you don't know at the start how many buttons there are going to be, you would be better off with a list.  Dim it like this:

     

    Dim Buttons As New List(Of Button)

     

    Add a new button to it like this:

     

    Dim B As New Button

    Buttons.Add(B)

     

    and move them like this:

     

    For Each Btn As Button In Buttons

    ' your code to move them here

    Next

    Sunday, February 17, 2008 7:53 PM
  • AHHHHH!! Thank you!! Now I can finnaly write what I want !! thank you again
    Sunday, February 17, 2008 10:32 PM