Reputation: 509
Visual Studio 2019, Visual Basic.
I have a Form. On load i add a lot of textbox. I need to hide layout during this process. I try:
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.SuspendLayout()
MakePanel() ' Sub adding textbox
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
But it showing all process. I Try
Private Sub Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Panel1.visible = false
MakePanel() ' Sub adding textbox
Me.Panel1.visible = true
End Sub
But nothing ...
Upvotes: 0
Views: 312
Reputation: 63
I don't have the rep to comment but your second attempt is on the right track. The problem likely lies in your MakePanel()
function not actually adding all the text boxes within Panel1
's control but rather as part of your form itself. So when you go to hide the panel, it doesn't hide the text boxes within it.
They need to be added via Panel1.Controls.Add
to actually 'hide' with Panel1
ie (starting with a new blank form):
Public Panel1 = New Panel()
Public TextBox1 = New TextBox()
Public TextBox2 = New TextBox()
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Controls.Add(Panel1)
Panel1.Visible = False
MakePanel()
Panel1.Visible = True
End Sub
Private Sub MakePanel()
Panel1.Location = New Point(3, 3)
Panel1.Name = "Panel1"
Panel1.Size = New Size(100, 100)
Panel1.TabIndex = 0
TextBox1.Location = New Point(3, 3)
TextBox1.Name = "TextBox1"
TextBox1.Size = New Size(49, 20)
TextBox1.TabIndex = 0
Panel1.Controls.Add(TextBox1)
TextBox2.Location = New Point(3, 29)
TextBox2.Name = "TextBox2"
TextBox2.Size = New Size(49, 20)
TextBox2.TabIndex = 1
Panel1.Controls.Add(TextBox2)
End Sub
Hope this helps!
Upvotes: 1