c# 怎样控制MDI子窗体在父窗体以及其上的控件之上
例如将Form1设置为父窗体,上面有1个pictureBox,两个Button控件,Form2,Form3是两个子窗体。当Form2和Form3弹出的时候,他们总是在pi...
例如将Form1设置为父窗体,上面有1个pictureBox,两个Button控件,Form2,Form3是两个子窗体。当Form2和Form3弹出的时候,他们总是在pictureBox和Button下面,这个怎么解决哦?
我的Form1代码是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool checkChildFrmExist(string childFrmName)
{
foreach (Form childFrm in this.MdiChildren)
{
if (childFrm.Name == childFrmName) //用子窗体的Name进行判断,如果存在则将他激活
{
if (childFrm.WindowState == FormWindowState.Minimized)
childFrm.WindowState = FormWindowState.Normal;
childFrm.Activate();
return true;
}
}
return false;
}
private void button1_Click(object sender, EventArgs e)
{
if (this.checkChildFrmExist("Form2") == true)
{
return;
}
else
{
Form2 f;
f = new Form2();
f.Show();
f.MdiParent = this;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (this.checkChildFrmExist("Form3") == true)
{
return;
}
else
{
Form3 f;
f = new Form3();
f.Show();
f.MdiParent = this;
}
}
}
} 展开
我的Form1代码是:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private bool checkChildFrmExist(string childFrmName)
{
foreach (Form childFrm in this.MdiChildren)
{
if (childFrm.Name == childFrmName) //用子窗体的Name进行判断,如果存在则将他激活
{
if (childFrm.WindowState == FormWindowState.Minimized)
childFrm.WindowState = FormWindowState.Normal;
childFrm.Activate();
return true;
}
}
return false;
}
private void button1_Click(object sender, EventArgs e)
{
if (this.checkChildFrmExist("Form2") == true)
{
return;
}
else
{
Form2 f;
f = new Form2();
f.Show();
f.MdiParent = this;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (this.checkChildFrmExist("Form3") == true)
{
return;
}
else
{
Form3 f;
f = new Form3();
f.Show();
f.MdiParent = this;
}
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询