C#中 在父窗体中新建子窗体的时候怎么关闭子窗体
比如父A建个子B我要再见个子C(前提是要在建C的同时关了B)在父窗体(form1)中新建子窗体(form2)点的是同一个按钮,在运行前,B和C都还没有生成呢。要得效果是运...
比如父A建个子B 我要再见个子C(前提是要在建C的同时关了B)
在父窗体(form1)中新建子窗体(form2)点的是同一个按钮,在运行前,B和C都还没有生成 呢。要得效果是运行时,点一下生成B再点一下就要删除B生成C 展开
在父窗体(form1)中新建子窗体(form2)点的是同一个按钮,在运行前,B和C都还没有生成 呢。要得效果是运行时,点一下生成B再点一下就要删除B生成C 展开
5个回答
展开全部
要考虑B被认为关掉的情况
Form f2 = new Form();
Form f3 = new Form();
bool IsForm2Showed = false;
bool IsForm3Showed = false;
bool IsClosedByButton = true;
private void button1_Click(object sender, EventArgs e)
{
if (!IsForm2Showed)
{
if (IsClosedByButton)
{
f2 = new Form();
f2.Text = "f2";
f2.FormClosed += new FormClosedEventHandler(f2_FormClosed);
f2.Show();
IsForm2Showed = true;
}
else
{
f3 = new Form();
f3.Text = "f3";
f3.FormClosed += new FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed = true;
}
}
else
{
if (!IsForm3Showed)
{
f2.Close();
IsClosedByButton = true;
f3 = new Form();
f3.Text = "f3";
f3.FormClosed += new FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed = true;
}
}
}
void f3_FormClosed(object sender, FormClosedEventArgs e)
{
IsForm3Showed = false;
}
void f2_FormClosed(object sender, FormClosedEventArgs e)
{
IsForm2Showed = false;
IsClosedByButton = false;
}
Form f2 = new Form();
Form f3 = new Form();
bool IsForm2Showed = false;
bool IsForm3Showed = false;
bool IsClosedByButton = true;
private void button1_Click(object sender, EventArgs e)
{
if (!IsForm2Showed)
{
if (IsClosedByButton)
{
f2 = new Form();
f2.Text = "f2";
f2.FormClosed += new FormClosedEventHandler(f2_FormClosed);
f2.Show();
IsForm2Showed = true;
}
else
{
f3 = new Form();
f3.Text = "f3";
f3.FormClosed += new FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed = true;
}
}
else
{
if (!IsForm3Showed)
{
f2.Close();
IsClosedByButton = true;
f3 = new Form();
f3.Text = "f3";
f3.FormClosed += new FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed = true;
}
}
}
void f3_FormClosed(object sender, FormClosedEventArgs e)
{
IsForm3Showed = false;
}
void f2_FormClosed(object sender, FormClosedEventArgs e)
{
IsForm2Showed = false;
IsClosedByButton = false;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要考虑B被认为关掉的情况
Form
f2
=
new
Form();
Form
f3
=
new
Form();
bool
IsForm2Showed
=
false;
bool
IsForm3Showed
=
false;
bool
IsClosedByButton
=
true;
private
void
button1_Click(object
sender,
EventArgs
e)
{
if
(!IsForm2Showed)
{
if
(IsClosedByButton)
{
f2
=
new
Form();
f2.Text
=
"f2";
f2.FormClosed
+=
new
FormClosedEventHandler(f2_FormClosed);
f2.Show();
IsForm2Showed
=
true;
}
else
{
f3
=
new
Form();
f3.Text
=
"f3";
f3.FormClosed
+=
new
FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed
=
true;
}
}
else
{
if
(!IsForm3Showed)
{
f2.Close();
IsClosedByButton
=
true;
f3
=
new
Form();
f3.Text
=
"f3";
f3.FormClosed
+=
new
FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed
=
true;
}
}
}
void
f3_FormClosed(object
sender,
FormClosedEventArgs
e)
{
IsForm3Showed
=
false;
}
void
f2_FormClosed(object
sender,
FormClosedEventArgs
e)
{
IsForm2Showed
=
false;
IsClosedByButton
=
false;
}
Form
f2
=
new
Form();
Form
f3
=
new
Form();
bool
IsForm2Showed
=
false;
bool
IsForm3Showed
=
false;
bool
IsClosedByButton
=
true;
private
void
button1_Click(object
sender,
EventArgs
e)
{
if
(!IsForm2Showed)
{
if
(IsClosedByButton)
{
f2
=
new
Form();
f2.Text
=
"f2";
f2.FormClosed
+=
new
FormClosedEventHandler(f2_FormClosed);
f2.Show();
IsForm2Showed
=
true;
}
else
{
f3
=
new
Form();
f3.Text
=
"f3";
f3.FormClosed
+=
new
FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed
=
true;
}
}
else
{
if
(!IsForm3Showed)
{
f2.Close();
IsClosedByButton
=
true;
f3
=
new
Form();
f3.Text
=
"f3";
f3.FormClosed
+=
new
FormClosedEventHandler(f3_FormClosed);
f3.Show();
IsForm3Showed
=
true;
}
}
}
void
f3_FormClosed(object
sender,
FormClosedEventArgs
e)
{
IsForm3Showed
=
false;
}
void
f2_FormClosed(object
sender,
FormClosedEventArgs
e)
{
IsForm2Showed
=
false;
IsClosedByButton
=
false;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在点击新建事件中输入
B.visable = false;
B.visable = false;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
A生成B A中写:form1 form2=new form1();form2.show()
B生成C,B中写:form2 form3=new form2();form2.hide();form3.show();
B生成C,B中写:form2 form3=new form2();form2.hide();form3.show();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
B.Hide();
C.Show();
C.Show();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询