有两个Form,点击button1出现Form1,Button2出现Form2,点击button3出现Form3…….问题是:
1.在Form1显示的时候,不用关闭Form1,点击其他按钮,关闭Form1并且,弹出另外的Form
2.如何使得点击按钮1出现form1,再点一下按钮1,关闭Form1.
1.在Form1显示的时候,不用关闭Form1,点击其他按钮,关闭Form1并且,弹出另外的Form
2.如何使得点击按钮1出现form1,再点一下按钮1,关闭Form1.
解决方案 »
- picturebox 显示图片问题
- 我做了个自动截图的软件,但是内存占用超高,怎么办?
- ArrayList中Add的一个问题求解
- 查询access数据库权限问题
- 使用属性的理由与线程同步
- 帮忙撇个WinForm下用户登录验证中,用户名和密码的约束条件。仿Windows登录模式。100分相送。。。
- 在C#windows程序时如何播放wav文件?
- 【串口】信息完整性的问题
- 关于gridView 在线=====================
- 高手帮忙:有没有谁做过什么控件,或是修改IE的内核,使得用浏览器打开邮件(.eml的文件,outlook接收的)时就可以直接显示该邮件的附件
- c#新手学习如何使用类
- 求助!!哪位高人会PHP,帮我把这段代码转成C#的啊?急求!
如何使窗体show出来时改变bool值?
public partial class Form1 : Form
{
Form f2 = null;
Form f3 = null;
Form f4 = null; private void button1_Click(object sender, EventArgs e)
{
f2 = new Form2();
f2.Show(); if (f3 is Form)
f3.Close(); if (f4 is Form)
f4.Close();
} private void button2_Click(object sender, EventArgs e)
{
f3 = new Form3();
f3.Show(); if (f2 is Form)
f2.Close(); if (f4 is Form)
f4.Close();
} private void button3_Click(object sender, EventArgs e)
{
f4 = new Form4();
f4.Show(); if (f2 is Form)
f2.Close(); if (f3 is Form)
f3.Close();
}
}
2.如何使得点击按钮1出现form1,再点一下按钮1,关闭Form1.
{
if(this.OwnedForms.Count>1)
{
Form oldform = this.OwnedForms[0];
oldform.Close();
if(oldform is Form1)
return;//如果关闭的窗口就是当前要打开的窗口,直接返回。
}
Form1 f = new Form1();
f.Owner = this;
f.Show();
}
其它按钮事件类似。
private void btn_form1_Click(object sender, EventArgs e)
{
if (frmThree != null)
{
frmThree.Close();
frmThree = null;
}
else if (frmTwo != null)
{
frmTwo.Close();
frmTwo = null;
}
else if (frmOne == null)
{
frmOne = FormOne.GetForm();
frmOne.Owner = this;
frmOne.Show();
}
} private void btn_form2_Click(object sender, EventArgs e)
{
if (frmThree != null)
{
frmThree.Close();
frmThree = null;
}
else if (frmOne != null)
{
frmOne.Close();
frmOne = null;
}
else if (frmTwo == null)
{
frmTwo = FormTwo.GetForm();
frmTwo.Owner = this;
frmTwo.Show();
}
} private void btn_form3_Click(object sender, EventArgs e)
{
if (frmTwo != null)
{
frmTwo.Close();
frmTwo = null;
}
else if (frmOne != null)
{
frmOne.Close();
frmOne = null;
}
else if (frmThree == null)
{
frmThree = FormThree.GetForm();
frmThree.Owner = this;
frmThree.Show();
}
}
测试过的