Adblock breaks this site

How do i open a new form when i click a button?

Discussion in 'Programming General' started by hampe-92, Sep 21, 2008.

  1. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    I need some help here... let's say I start out with a form, called "Form1"
    when I have edited that so it looks just like I want it, then I want to make it open a form called "Form2" when I click a button... how can I possibly do that??
    thx in advance!:)
     
  2. Flaming Idiots

    Flaming Idiots Active Member
    Visual Basic Programmers

    Joined:
    Dec 22, 2005
    Posts:
    235
    Referrals:
    1
    Sythe Gold:
    0
    Two Factor Authentication User
    How do i open a new form when i click a button?

    You need to create a new form and call its Show method.

    Code:
    private void button_Click(object sender, EventArgs e)
    {
        Form form = new Form();
        form.Show();
    }
     
  3. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    yay it works :D tyvm!:)

    EDIT: hmm :/ i wrote:
    Code:
    private void button_Click(object sender, EventArgs e)
    {
        Form Form2 = new Form();
        Form2.Show();
    }
    and that opens up a new form, but not my form, "Form2", that i have made... it just opens a blank new form :confused:
     
  4. Flaming Idiots

    Flaming Idiots Active Member
    Visual Basic Programmers

    Joined:
    Dec 22, 2005
    Posts:
    235
    Referrals:
    1
    Sythe Gold:
    0
    Two Factor Authentication User
    How do i open a new form when i click a button?

    It should be:
    Code:
    Form2 form = new Form2();
     
  5. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    ohh tysm for the help! now it's working just as it is suposed to!:)
     
  6. BigBwoi2001

    BigBwoi2001 Member

    Joined:
    Jul 4, 2008
    Posts:
    54
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    Code:
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(New FormName());
    this.hide();
     
  7. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    thx but it works just fine that way Flaming said.. ;)
    and beside, i don't want form1 to be closed when i open form2 :p but thx anyway, it might come in handy l8er some time:)
     
  8. BigBwoi2001

    BigBwoi2001 Member

    Joined:
    Jul 4, 2008
    Posts:
    54
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    Well incase you wanted to close form1 you could use that method also.
     
  9. hampe-92

    hampe-92 Forum Addict

    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0
    How do i open a new form when i click a button?

    what u mean? your or his method?
     
< Which language? | Htaed Searcher >


 
 
Adblock breaks this site