一、解决同一窗体多次点击重复显示BUG
(1)点击弹出学校窗体
#region 弹出学校窗体
/// <summary>
/// 弹出学校窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SchoolToolStripMenuItem_Click(object sender, EventArgs e)
{
//点击后显示SchoolTan这个弹窗
SchoolTan schooltanchuang=new SchoolTan(); //this.IsMdiContainer = true;
//WFromMain mainForm = new WFromMain();
//schooltanchuang.MdiParent = this;
/*
* 方法:明确父子关系:
son form = new Form();
form.MdiParent = this(father);
form.show();
前提是先要设置father窗体
isMdiContainer = true;
* **/
if (this.MdiChildren==null||this.MdiChildren.Length==)
{
schooltanchuang.Show();
//让子窗体不超出父窗体界限,给子窗体指定父窗体
schooltanchuang.MdiParent = this;
return;
}
bool flag = false;
foreach (var item in this.MdiChildren)
{
if (item.Text == schooltanchuang.Text)
{
schooltanchuang = item as SchoolTan;
schooltanchuang.Activate();
flag = true;
break;
}
}
if (!flag)
{
schooltanchuang.Show();
//给子窗体指定父窗体
schooltanchuang.MdiParent = this;
}
}
#endregion
(2)弹出商会组织窗体
#region 弹出商会组织窗体
/// <summary>
/// 弹出商会组织窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ShanghuiToolStripMenuItem_Click(object sender, EventArgs e)
{
//点击弹出重庆商会窗体
ShangHui shang = new ShangHui();
//shang.Show();
//shang.MdiParent = this;
if (this.MdiChildren == null || this.MdiChildren.Length == )
{
shang.Show();
//让子窗体不超出父窗体界限,给子窗体指定父窗体
shang.MdiParent = this;
return;
}
bool flag = false;
foreach (var item in this.MdiChildren)
{
if (item.Text == shang.Text)
{
shang = item as ShangHui;
shang.Activate();
flag = true;
break;
}
}
if (!flag)
{
shang.Show();
//给子窗体指定父窗体
shang.MdiParent = this;
}
}
#endregion
(3)点击弹出公益组织窗体
#region 点击弹出公益组织窗体
/// <summary>
/// 点击弹出公益组织窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 公益组织ToolStripMenuItem_Click(object sender, EventArgs e)
{
//点击弹出公益组织窗体
GongYi gongyi = new GongYi();
//gongyi.Show();
//gongyi.MdiParent = this;
if (this.MdiChildren == null || this.MdiChildren.Length == )
{
gongyi.Show();
//让子窗体不超出父窗体界限,给子窗体指定父窗体
gongyi.MdiParent = this;
return;
}
bool flag = false;
foreach (var item in this.MdiChildren)
{
if (item.Text == gongyi.Text)
{
gongyi = item as GongYi;
gongyi.Activate();
flag = true;
break;
}
}
if (!flag)
{
gongyi.Show();
//给子窗体指定父窗体
gongyi.MdiParent = this;
}
}
#endregion
二、关闭所有的运行环境操作
/// <summary>
/// 关闭运行环境
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 关闭全部窗体ToolStripMenuItem_Click(object sender, EventArgs e)
{
//关闭运行环境
Environment.Exit();
}
三、右键菜单关闭所有弹窗(右键菜单有多个选项时的情况)
private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{ int len = this.MdiChildren.Length;
for (int i = ; i <len ; i++)
{
Form frm = this.MdiChildren[];
frm.Close();
}
}
四、获取radiobatton的text值的方法
private void btnNanNv_Click(object sender, EventArgs e)
{
string checkedRBName = ""; //取得选中单选按钮的名称
if (radioButtonMan.Checked)
{
checkedRBName = radioButtonMan.Name;
string textNan = radioButtonMan.Text;
MessageBox.Show("这是选中了"+textNan);
}
else if (radioButtonGirl.Checked)
{
checkedRBName = radioButtonGirl.Name;
string textNv = radioButtonGirl.Text;
MessageBox.Show("这是选中了"+ textNv);
//获得和radioButton按钮对应标签的内容,用的是 radioButton2.Text属性; } MessageBox.Show(checkedRBName + " was checked.");
}