Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VisualStudio
i'm creating a project. there i first created a parent form. then i loaded 2 panels and in the parent form.
and i created a 3 forms with different functionality.
i successfully loaded form1 in panel1. i need to load a form in panel2 when a button is clicked in form1 that is loaded in panel1.
please help me to complete this.
thanks in advance...,
Posted 25-Aug-12 17:01pm
Edited 25-Aug-12 17:33pm
v2
Comments
Wes Aday at 25-Aug-12 22:25pm
   
Well from your very vague description you want Form2 frm2 = new Form2(); frm2.Show(); or ShowDialog().
prabah.02 at 25-Aug-12 22:31pm
   
this is not working..,
i want to load a form in panel...,
when i click a button in form1(loaded in panel1) a form needs to load in panel2
Wes Aday at 25-Aug-12 22:40pm
   
That makes no sense. You are not going to be loading a form in a panel. You probably mean you want to load a user control?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Mohamed Mitwalli at 26-Aug-12 1:39am
   
5+
nitin bhoyate at 26-Aug-12 5:42am
   
thanks go ahead.....Keep coding...
Mohamed Mitwalli at 26-Aug-12 6:02am
   
lol thanks for advice
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

loading form inside panel
inside button's click event, write code as below
form2 frm = new form2();
frm.Toplevel = false;
pnl2.controls.add(frm);
frm.show();
Happy Coding!
Smile | :)
  Permalink  
v2
Comments
Mohamed Mitwalli at 26-Aug-12 6:00am
   
Top-level control cannot be added to control Well this is the Error
message will appear your missing this line of code
frm.TopLevel = false ;
So i voted 1
aarti meswania at 26-Aug-12 9:01am
   
oh! yes really it is.
that line is very important else whole code is meaning less.
thanks for your honest decision-downvoting!
:)
Mohamed Mitwalli at 26-Aug-12 9:13am
   
But unfortunately people not reading the answers or the comment another solution has been added with the same Error :(
aarti meswania at 26-Aug-12 9:27am
   
hmm,
I have 'improve solution' of our both.
so, ok now?
Mohamed Mitwalli at 26-Aug-12 9:45am
   
yes Thanks :)
aarti meswania at 26-Aug-12 9:46am
   
welcome :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

panl2.controls.clear();
 
form2 frm = new form2();
frm.TopLevel = False;
pnl2.controls.add(frm);
frm.show();
  Permalink  
v3
Comments
Mohamed Mitwalli at 26-Aug-12 9:15am
   
Top-level control cannot be added to control Well this is the Error message will appear your missing this line of code frm.TopLevel = false ; So i voted 1
Could you in the next time Read the Solution that provide by other developer maybe it will help you .
aarti meswania at 26-Aug-12 9:41am
   
hi! one line was missing here so, I have added it using 'improve solution' link
line was 'frm.TopLevel = false;',
because, form is default top level control so, if we don't write this line it will give error.
 
now, both of our solutions are working!
that is good effort to answer question. keep it up.
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 26 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100