locked
Simple C# question RRS feed

  • Question

  • I apologize for the newbie in me, but it has been a while since I've programmed.  I am just wanting to know how to call a form when a button is clicked.  I have the form created, I just need the form to appear when the button is clicked.  I've searched throughout this forum and couldnt find anything, I apologize if this is a repost.  Thank you for your help.
    Thursday, August 6, 2009 9:41 PM

Answers

  • EngineForm ef = new EngineForm();
    ef.show();
    Put these 2 lines in the button_click event handler.

    TK
    • Proposed as answer by Figo Fei Monday, August 10, 2009 10:03 AM
    • Marked as answer by derrickwhitt Monday, August 10, 2009 5:49 PM
    Friday, August 7, 2009 3:30 PM

All replies

  • If you want to the form to appear (and you have already created/initialized it), just call Form.Show()

    Example:

    // In the constructor (or designer) for the form containing the button:
    this.button1.Click += new System.EventHandler(this.button1_Click);
    
    Form myForm = new Form(); // initialize the form (can be almost anywhere)
    
    // At the class-level
    private void button1_Click(object sender, EventArgs e)
    {
        myForm.Show();
    }

    This message is brought to you by the letter C.
    • Proposed as answer by Figo Fei Monday, August 10, 2009 10:03 AM
    Thursday, August 6, 2009 9:51 PM
  • Here is my project - I am wanting to call the Engineform when the button Engines is clicked
    http://www.mediafire.com/?sharekey=c776419ce439d1f2d1014a7a667fa2b4e04e75f6e8ebb871
    It is called DouglasFire.zip

    Thanks!
    Thursday, August 6, 2009 11:07 PM
  • Derrick,

    I'm not going to download that ZIP file and sift through all of your code. If there is a particular section of your code that you have a question about, you can post a snippet here in the thread.
    This message is brought to you by the letter C.
    Friday, August 7, 2009 2:48 PM
  • EngineForm ef = new EngineForm();
    ef.show();
    Put these 2 lines in the button_click event handler.

    TK
    • Proposed as answer by Figo Fei Monday, August 10, 2009 10:03 AM
    • Marked as answer by derrickwhitt Monday, August 10, 2009 5:49 PM
    Friday, August 7, 2009 3:30 PM