new form without new window
-
i have 3 forms and a toolbar with 3 buttons. Form1, Form2, Form3, tbbForm1, tbbForm2, tbbForm3 i want the toolbar buttons to switch between these 3 forms. the problem i'm having is that each time i press a button, it opens the form in a new window.
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if(e.Button == this.tbbForm1) { Form1 frm1 = new Form1(); this.frm1.Show(); } else if(e.Button == this.tbbForm2) { Form2 frm2 = new Form2(); this.frm2.Show(); } else if(e.Button == this.tbbform3) { Form3 frm3 = new Form3(); this.frm3.Show(); } } [/code] i know my code calls on a new object each time the button is pressed. i have tried instantiating each of the forms in the constructor so i could just use the Show() method, but this does not work. please help! =)
-
i have 3 forms and a toolbar with 3 buttons. Form1, Form2, Form3, tbbForm1, tbbForm2, tbbForm3 i want the toolbar buttons to switch between these 3 forms. the problem i'm having is that each time i press a button, it opens the form in a new window.
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if(e.Button == this.tbbForm1) { Form1 frm1 = new Form1(); this.frm1.Show(); } else if(e.Button == this.tbbForm2) { Form2 frm2 = new Form2(); this.frm2.Show(); } else if(e.Button == this.tbbform3) { Form3 frm3 = new Form3(); this.frm3.Show(); } } [/code] i know my code calls on a new object each time the button is pressed. i have tried instantiating each of the forms in the constructor so i could just use the Show() method, but this does not work. please help! =)
Erm, what happens if you instantiate all three forms, the for each button do something like this: frm1.Show(); frm2.Hide(); frm3.Hide(); On the other hand, if you're toolbar is doing this, why not instead use a tab control and tab pages? Marc STL, a liability factory - Anonymously
A doable project is one that is small enough to be done quickly and big enough to be interesting - Ken Orr
Latest AAL Article My blog -
i have 3 forms and a toolbar with 3 buttons. Form1, Form2, Form3, tbbForm1, tbbForm2, tbbForm3 i want the toolbar buttons to switch between these 3 forms. the problem i'm having is that each time i press a button, it opens the form in a new window.
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if(e.Button == this.tbbForm1) { Form1 frm1 = new Form1(); this.frm1.Show(); } else if(e.Button == this.tbbForm2) { Form2 frm2 = new Form2(); this.frm2.Show(); } else if(e.Button == this.tbbform3) { Form3 frm3 = new Form3(); this.frm3.Show(); } } [/code] i know my code calls on a new object each time the button is pressed. i have tried instantiating each of the forms in the constructor so i could just use the Show() method, but this does not work. please help! =)
mikemilano wrote: i know my code calls on a new object each time the button is pressed. i have tried instantiating each of the forms in the constructor so i could just use the Show() method, but this does not work. The reason why is you must first define it like so
public class Form1 { private Form2 fm; public Form1() { fm = new Form2(); } public void Button1_Click( object sender, EventArgs e ) { fm.Show(); } }
thats all there is to it I'm not an expert yet, but I play one at work. Yeah and here too.