Home > Blockchain >  How to move multiple panels as one in vb?
How to move multiple panels as one in vb?

Time:12-19

I am making an application in Visual Basic as I am new to programming. I am trying to get it to be like wordle. After a user inputs a word, a panel box is made and multiple labels are placed inside of the panel box. Now for future guesses, I need to move that panel box down and place the new panel box in the original spot. To sum it up, newest panels show up at the top and oldest panels show up at the bottom.

Because a new panel is being made each time I just tried to simply move it before making a new one, did not work. If any code is required to help me I would be happy to provide it.

CodePudding user response:

You should use a FlowLayoutPanel as a container for the other Panel controls. You can simply add a child control to it and it will handle the layout, so you don't have to worry about setting or changing the Location of each child. If you use myFlowLayoutPanel.Controls.Insert and specify 0 as the index, the new child control will be placed at the start and all other children will be pushed down automatically.

CodePudding user response:

Use the Location Property to move Controls

   'create new Panel object
    Dim newPanel As Panel = New Panel
    newPanel.Size = New System.Drawing.Size(width:=300, height:=300)
    'place Location
    newPanel.Location = New Point(x:=10, y:=10)
    'add Panel object to Form
    Me.Controls.Add(newPanel)

    'create new Label
    Dim newLabel As Label = New Label
    'add Label to Form

    newLabel.Text = "I Am new"
    newLabel.Location = New Point(20, 20)
    'Add Label to panel
    newPanel.Controls.Add(newLabel)
    'move panel
    newPanel.Location = New Point(x:=10, y:=100)
  • Related