Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Dialogs and Forms

jmusyjjmusyj Posts: 33Member
If I have a program that has a main form (Form1) and when the user clicks a button on Form1 it opens up another form (Form2) as a dialog, how can I set a button on Form2 to close just Form2 (not the whole program) and go back into Form1. Also, when I have Form2 open, I don't want the user to be able to access Form1. Anyone know how to accomplish these things? Thanks in advance....

Comments

  • BaldusariusBaldusarius Posts: 162Member
    : If I have a program that has a main form (Form1) and when the user clicks a button on Form1 it opens up another form (Form2) as a dialog, how can I set a button on Form2 to close just Form2 (not the whole program) and go back into Form1. Also, when I have Form2 open, I don't want the user to be able to access Form1. Anyone know how to accomplish these things? Thanks in advance....
    :

    // In Form1
    Form2 frm2 = new Form2();
    frm2.ShowDialog(); // frm2 will be show modally

    // In Form2
    void Button_Click(object sender, EventArgs e)
    {
    // close current instance and
    // return control to calling code (Form1)
    Close();
    }
  • jmusyjjmusyj Posts: 33Member
    Excellent, works perfect. Thanks a bunch Baldusarius!

    : : If I have a program that has a main form (Form1) and when the user clicks a button on Form1 it opens up another form (Form2) as a dialog, how can I set a button on Form2 to close just Form2 (not the whole program) and go back into Form1. Also, when I have Form2 open, I don't want the user to be able to access Form1. Anyone know how to accomplish these things? Thanks in advance....
    : :
    :
    : // In Form1
    : Form2 frm2 = new Form2();
    : frm2.ShowDialog(); // frm2 will be show modally
    :
    : // In Form2
    : void Button_Click(object sender, EventArgs e)
    : {
    : // close current instance and
    : // return control to calling code (Form1)
    : Close();
    : }
    :

Sign In or Register to comment.