Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. new form without new window

new form without new window

Scheduled Pinned Locked Moved C#
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikemilano
    wrote on last edited by
    #1

    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! =)

    M I 2 Replies Last reply
    0
    • M mikemilano

      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! =)

      M Offline
      M Offline
      Marc Clifton
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M mikemilano

        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 Offline
        I Offline
        Ista
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups