当前位置: 动力学知识库 > 问答 > 编程问答 >

Issue with a vb.net panel control loop

问题描述:

I have a loop in vb.net where I am wanting to display 50 panels, all with the same 3 controls. Only the last control is populated with the 3 controls, why is this?

 Dim PanelVerticalPoint As Integer = btDF.Height * 6

For counter = 1 To 50 Step +1

Dim ButtonPanel As Panel = New Panel

With ButtonPanel

ButtonPanel.Location = New Point(0, PanelVerticalPoint)

ButtonPanel.Size = New Size(btDF.Width, btDF.Height)

Me.Controls.Add(ButtonPanel)

ButtonPanel.Controls.Add(btCustomButtonMenu)

ButtonPanel.Controls.Add(btCustomTextBox)

ButtonPanel.Controls.Add(btCustomButton)

End With

PanelVerticalPoint = PanelVerticalPoint + btDF.Height

Next counter

网友答案:

You have to add a new instance of the buttons to each panel. You are adding the same button instance to the panels so each add is really moving the button.

网友答案:

It's not easy to clone a control. It looks like your case might be appropriate for a user control instead. Make the user control in the designer with the buttons and text box, then just create many instances of the user control instead of the panel.

Here's a very similar question with that kind of answer Clone Winform control

分享给朋友:
您可能感兴趣的文章:
随机阅读: