Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have 4 forms..

 

MAINFORM..

 

FORM1

FORM2

FORM3

 

 

In my mainForm .. I have 3 button and 1 panel...

 

I want to create application in which..

 

If i click button1.. PANEL will display form1..

 

if i click button2 .. panel will display form2..

 

if i click button3 .. panel will display form3...

Posted

Maybe try this

 

Probably being the Laziest programmer in the known universe...

 

When I need to do something like this in VS10

 

  • I design a from in the designer
  • I change the inherited item from form to panel
  • I modify InitializeComponent() in the designer code, to start as a panel instead of a form

 

Now just add the new panels to your form and make them visible and invisible as you like.

 

This works quite well, Quick and dirty :)

Posted

Of course, you are right... as usual :D

 

Can't remember why I started doing something stupid like this in the first place.

 

I only recently started programming again, after a break of a year or so... Must still be rusty

  • 2 weeks later...
Posted (edited)

I found the solution.. .

 private void MainForm_Load(object sender, EventArgs e)
       {
           this.btn_show1.Click += new EventHandler(btn_show_Click);
           this.btn_show2.Click += new EventHandler(btn_show_Click);
           this.btn_show3.Click += new EventHandler(btn_show_Click);
       }

       void btn_show_Click(object sender, EventArgs e)
       {
           this.pnl_ShowForms.Controls.Clear();
           int tag = Convert.ToInt32( (sender as Button).Tag);
           switch (tag)
           {
               case 1:
                   Form1 frm1 = new Form1();
                   frm1.FormBorderStyle = FormBorderStyle.None;
                   frm1.Dock = DockStyle.Fill;
                   frm1.WindowState = FormWindowState.Maximized;
                   frm1.TopLevel = false;
                   this.pnl_ShowForms.Controls.Add(frm1);
                   frm1.Show();
                   break;
               case 2:
                   Form2 frm2 = new Form2();
                   frm2.FormBorderStyle = FormBorderStyle.None;
                   frm2.Dock = DockStyle.Fill;
                   frm2.WindowState = FormWindowState.Maximized;
                   frm2.TopLevel = false;
                   this.pnl_ShowForms.Controls.Add(frm2);
                   frm2.Show();
                   break;
               case 3:
                   Form3 frm3 = new Form3();
                   frm3.FormBorderStyle = FormBorderStyle.None;
                   frm3.Dock = DockStyle.Fill;
                   frm3.WindowState = FormWindowState.Maximized;
                   frm3.TopLevel = false;
                   this.pnl_ShowForms.Controls.Add(frm3);
                   frm3.Show();
                   break;
           }
       }

Edited by snarfblam
  • Leaders
Posted
If you're going to be using these exactly like controls, why would you create them as forms? It's no extra effort to use a UserControl instead. All you are doing is opening yourself up to the possibility of quirky or problematic unexpected behavior.
[sIGPIC]e[/sIGPIC]
  • 1 month later...
Posted

An alternative: you could set your application's main form to be a MDI container, where your main form houses all other MDI child forms. Pretty much like a traditional image processor (Photo Shop) if you don't know what I'm talking about. By using this you could easily open / close and set the position of all windows through the buttons you described.

 

http://msdn.microsoft.com/en-us/library/d4dabts7%28v=vs.80%29.aspx

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...