The NewForm did not close itself when every time i called a "New Form", but the Main Form does
Hi everyone, i have a problem. I already can closed the MainForm when i called the FirstForm, but when i called a "NewForm" again in the FirstForm, it called the SecondForm, but the FirstForm did not closed, so i have a 2 forms on my taskbar.
How do i fix that?
Here is the code:
private void AddNewForm(object sender, EventArgs e)
{
Form newForm = new Form();
AddObjects(sender, e, newForm);
UpdateTextPosition(sender, e);
newForm.Size = new Size(1360, 735);
newForm.Text = "Selling System";
newForm.FormBorderStyle = FormBorderStyle.Fixed3D;
newForm.AutoScaleMode = AutoScaleMode.Font;
newForm.AutoScroll = true;
newForm.AutoSizeMode = AutoSizeMode.GrowAndShrink;
newForm.StartPosition = FormStartPosition.Manual;
newForm.Location = new Point(0, 0);
newForm.MaximizeBox = false;
newForm.Controls.Add(label1);
newForm.Controls.Add(label2);
newForm.Controls.Add(label3);
newForm.Controls.Add(label4);
newForm.Controls.Add(label5);
newForm.Controls.Add(label6);
newForm.Controls.Add(label7);
newForm.Controls.Add(menuStrip1);
CloseForm(sender, e);
newForm.ShowDialog();
}
private void CloseForm(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
Action act = () =>
{
this.Hide();
};
this.Invoke(act);
}
else
{
this.Hide();
}
}
Thanks in advance!