在.Net WinForms 我有两种形式。Form1 已打开且处于活动状态。如何打开新表单 (Form2):
- Form1 必须有焦点
- Form2在Form1下打开(后台Form1)
第一点很简单,请参阅stackoverflow ... 但我不知道如何在Form1下显示Form2。谢谢。
编辑
public partial class Form1 : Form
{
Form2 frm;
public Form1()
{
InitializeComponent();
frm = new Form2();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Focus();
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.AddOwnedForm(frm);
frm.Show();
frm.SendToBack();
this.BringToFront();
}
private void button1_Click(object sender, EventArgs e)
{
frm.Show();
frm.SendToBack();
this.BringToFront();
}
}
表格2
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
textBox1.Focus();
}
protected override bool ShowWithoutActivation
{
get
{
return true;
}
}
protected override CreateParams CreateParams
{
get
{
//make sure Top Most property on form is set to false
//otherwise this doesn't work
int WS_EX_TOPMOST = 0x00000008;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TOPMOST;
return cp;
}
}