C# 想让子窗体随主窗体移动而移动
就在 private void button1_Click(object sender, EventArgs e)
{
Form f = new Form2();
f.Show();//弹出form2
f.StartPosition = FormStartPosition.Manual;
f.Left = this.Left + this.Width;
f.Top = this.Top;//设置form2位置
}
private void Form1_Move(object sender, EventArgs e)
{
Form f = new Form2();
f.Location = new Point(this.Location.X + this.Width, this.Location.Y);//form2随着form1移动
}
不知道为什么不正确,只能实现form2挨着form1 不能随其form1移动而移动
请哪位大神帮忙改下,让我能实现这个功能!!!
------解决方案--------------------
C# code
Form f = new Form2();
private void button1_Click(object sender, EventArgs e)
{
f.Show();//弹出form2
f.StartPosition = FormStartPosition.Manual;
f.Left = this.Left + this.Width;
f.Top = this.Top;//设置form2位置
}
private void Form1_Move(object sender, EventArgs e)
{
f.Location = new Point(this.Location.X + this.Width, this.Location.Y);//form2随着form1移动
}