Dialogs and Forms - Programmers Heaven

Howdy, Stranger!

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

Categories

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.