Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir/ Madam

I have created C# Project using Visual Studio IDE Technology. On this project I have created 2 Forms, and my slight problem is as follows:.

Basicly on Form1 when I click cmdTab1 button it calls Form2.

On Form2 I have 2 buttons (OK, and CANCEL), when I click OK button it does the job (it makes the Panel visible to false on Form1), but when I click CANCEL button it does close the Form2 (which is what i want) but for some reason it shows me some other components from Form1 to visible true (I mean it shows visible=true the other 2 Panels that I have them on Form1).

Here is some of that code from Form2


FORM2

C#
public partial class NumberOfCovers : Form
{
    private Panel cP;

public NumberOfCovers()
{
   InitializeComponent();
}

public NumberOfCovers(Panel p)
{
   InitializeComponent();
   cP = p;
}
      
private void cmdOk_Click(object sender, EventArgs e)
{
   cP.Visible = false;
   this.Close(); 
}

private void cmdCancel_Click(object sender, EventArgs e)
{
      /* Here im having the dificulty */
      this.Close();
}
}

Here is the other code from Form1

FORM1

C#
private void cmdTab1_Click(object sender, EventArgs e)
{
      NumberOfCovers numcov = new NumberOfCovers(this.ButtonTablesPanel);
      numcov.ShowDialog();
      TableOrderPanel.Visible = true;
      FlowLayoutPanelUserFunctions.Visible = false;
      SendOrderPanel.Visible = true;

}

Now I don't understand what is wrong, but all I want is that when i click CANCEL button on Form2 I want to close Form2 only and nothing else...

Any help would be gratfull. Thanks in advance...

Kind regards

RONI
Posted
Updated 19-Nov-10 10:06am
v2
Comments
LAPEC 19-Nov-10 16:24pm    
Thanks a lot John that was very very helpfull...

1 solution

You want to do this:

C#
private void cmdTab1_Click(object sender, EventArgs e)
{
    NumberOfCovers numcov = new NumberOfCovers(this.ButtonTablesPanel);
    DialogResult result = numcov.ShowDialog();
    if (result == DialogResult.OK)
    {
        TableOrderPanel.Visible = true;
        FlowLayoutPanelUserFunctions.Visible = false;
        SendOrderPanel.Visible = true;
    }
}


In form2, you may need to do this:

C#
private void cmdOk_Click(object sender, EventArgs e)
{
    cP.Visible = false;
    this.DialogResult = DialogResult.OK;
    this.Close(); 
}

private void cmdCancel_Click(object sender, EventArgs e)
{
    this.DialogResult = DialogResult.Cancel;
    this.Close();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900