0

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 ...

DerStarkeBaer
  • 669
  • 8
  • 28
IfThenElse
  • 485
  • 5
  • 13
  • I find this https://stackoverflow.com/questions/13122994/why-is-adding-suspendlayout-and-resumelayout-reducing-performance now i test – IfThenElse Sep 13 '19 at 08:36
  • It is a pretty nasty bug in the program, the window must not yet be visible while the Load event runs. It is possible, but guessing isn't likely to get you to move ahead. This kind of code belongs in the constructor (Sub New), aiming there also increases the odds of finding the bug. – Hans Passant Sep 13 '19 at 09:12

1 Answers1

1

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!

gen_angry
  • 63
  • 1
  • 7