I am using Microsoft Visual Studio creating a Windows Form Application. **I don't know how I should add my User Controls to my Form.** I have seen many examples on how you can do it, but I am yet to find an answer that takes performance into account, atleast that's what I believe.
Here are the two methods that I have used:
1. **UserControl.Visible = True / False**
One of the more common methods that I have seen is to place your User Control in your Form and setting the visibility to False. Whenever the User Control needs to be visible you simply set Visible to True. I personally feel that this is a very bad way to handling User Controls. This can become very disorienting when you have a lot of controls in your Form. *This is the method I was taught to use.*
The code can look something like this:
Public Class Form_Main
Private Sub Button_Visible_Click(sender As Object, e As EventArgs) Handles Button_Visible.Click
UserControl_1.Visible = True
End Sub
End Class
2. **Load User Control "Dynamically"**
Loading a User Control dynamically implies that I add the User Control to a container (Panel, etc.)
The code can look something like this:
Public Class Form_Main
Public Shared UC_Main As New UserControl_Main
Private Sub Form_Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Panel_Container.Controls.Add(UC_Main)
End Sub
End Class
**The question about Performance and Method**
What methods of adding and disposing User Controls are most efficient in terms of performance?
What I have tried:
I have tried both of the alternatives above, but are still confused on how I should do this.