mrdutchie Posted September 5, 2003 Posted September 5, 2003 Must be very simple but I can't figure it out. I have a panel with a form loaded. I want to get rid of the form within that panel, when I push on a button outside that panel. Thought I use a Clear function, like panel1.clear but that ain't there... Is there a easy way to clear a panel? Quote
sjn78 Posted September 7, 2003 Posted September 7, 2003 I am a confused about what it is you are doing. Do you have 2 forms, Form A has a panel and within that panel FormB is shown? If this is the case, let me know as I am would like to know how it is done. Quote
mrdutchie Posted September 7, 2003 Author Posted September 7, 2003 That's correct :-) And I can't do a form.dispose within that panel. so I need something to clear the panel, cause the form name etc. it not recognized elsewhere in my code. And this is how you create a form within a panel on another form.. I have a mainform with 3 panels. ala Outlook Style. panel 40 is the right panel for me, and thats where everything is happening. I have a button on the left site, and this is what's underneath that button. Dim addressbook As Form addressbook = New Frmaddressbook addressbook.TopLevel = False addressbook.Dock = DockStyle.Fill addressbook.Parent = Panel40 addressbook.Show() Good luck Quote
sjn78 Posted September 7, 2003 Posted September 7, 2003 I found how to do it on another website. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As New Form2() frm.TopLevel = False Panel1.Controls.Add(frm) frm.Show() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Panel1.Controls.Clear() End Sub This works for me, but only problem I have is on resize, the form on the panel will not move with the panel size. I have tried anchoring and docking, but none will work Quote
aewarnick Posted September 7, 2003 Posted September 7, 2003 If it does not automatically resize or move the Form you will have to manually do it. Override OnResize making sure to call the base and resize the Form manually there. Quote C#
sjn78 Posted September 7, 2003 Posted September 7, 2003 Umm......I havn't ventured into overrides yet. Will this override be in the main form or in the form being displayed in the panel? Is it possible to give me what should be in the sub to perform this? Thanks Quote
aewarnick Posted September 7, 2003 Posted September 7, 2003 Whichever form resizes first. After one resizes you can set the size of the other, if you want. I only know C syntax not VB, you will have to translate. protected override void OnResize(EventArgs e) { base.OnResize(e); **Your code here** **maybe something like** form2.Size= form1.Size; } You wouldn't even have to use that. It is just less writing than hooking up an event (OnResize event) and in my opinion, faster code. Quote C#
Hamburger1984 Posted September 7, 2003 Posted September 7, 2003 see attachment... this should answer you questions.... Andreasforminpanel.zip Quote
sjn78 Posted September 8, 2003 Posted September 8, 2003 I was pulling my hair out for ages trying to get it to work. I had my sub forms Window State set to maximized (thinking it would fill the entire panel) and it wouldn't work. I changed them to normal and it goes fine. Sneaky little things........ Quote
mrdutchie Posted September 8, 2003 Author Posted September 8, 2003 YES!!! Panel40.Controls.Clear() was the one I was looking for... Thanks so much. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.