In one of my event, I DISPOSE the panels in a form. The question I'm having is, how do I bring the panels back into the form? The panels are created at design time.
Many thanks in advance!
ljCharlie
Printable View
In one of my event, I DISPOSE the panels in a form. The question I'm having is, how do I bring the panels back into the form? The panels are created at design time.
Many thanks in advance!
ljCharlie
If you have already disposed them then you'll need to recreate them to get them back.
What's the best way to accomplish this? Here's what I want to do. In those individual panels, I have certains textboxes and datagrid etc.. When I'm done with one panel, I don't want to keep it in memory...such as just hide them or sent the panel to the back. I want to somehow free those memory. What's my best option?
If I do need to recreate them, since I design those panels in design time, can I just call it back?
Many thaks for the help!
ljCharlie
You don't, unless you create new instances of them again.
You could just set Panel.Visible=false
Or you could define the panel on the Form Level, and simply add /remove it to the Form's control collection as you see fit (see example below)
VB Code:
Private x As New Panel Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.Controls.Add(x) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.Controls.Remove(x) End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim c As New Label c.Text = "created by panel" c.Visible = True x.Visible = True x.Controls.Add(c) End Sub
My post was in regards to your first post, not your response btw.
You could create a inherited Panel class, that you design those controls on, and simply create instances and dispose of instances as you see fit, so then, you don't even need to add controls to the panels on the fly (only at design time).
Thank you very much, nemaroller! I guess I can use Remove instead of Dispose. However, what's the different and best way to free up some memory?
ljCharlie
nemaroller, mind giving me a sample of creating a inherited Panel class? I'm quite new to this VB.NET thing.
Well, if creating an inherited panel class is too cumbersome then I guess I could settle down for the remove thing.
Your help is greatly appreciated!
ljCharlie
Right-Click your Project in your solution explorer, click Add User Control.
Give it an appropriate name.
When you are done adding controls where you want them:
Right-Click the new User Control and choose View Code
Where it says Inherits Windows.Forms.UserControl,
change that to:
Inherits Windows.Forms.Panel
Thanks! I'll give that a consideration too. By the way, if I use remove, will that free up the memory that's being taken by the panels?
ljCharlie