|
-
Nov 14th, 2003, 03:44 PM
#1
Thread Starter
Addicted Member
How to bring back the panel
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
-
Nov 14th, 2003, 03:46 PM
#2
If you have already disposed them then you'll need to recreate them to get them back.
-
Nov 14th, 2003, 03:50 PM
#3
Thread Starter
Addicted Member
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
-
Nov 14th, 2003, 03:51 PM
#4
I wonder how many charact
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
-
Nov 14th, 2003, 03:54 PM
#5
I wonder how many charact
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).
-
Nov 14th, 2003, 03:54 PM
#6
Thread Starter
Addicted Member
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
-
Nov 14th, 2003, 03:59 PM
#7
Thread Starter
Addicted Member
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
-
Nov 14th, 2003, 04:06 PM
#8
I wonder how many charact
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
-
Nov 17th, 2003, 09:18 AM
#9
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|