读书人

C# 念让子窗体随主窗体移动而移动

发布时间: 2012-10-21 09:00:07 作者: rapoo

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移动      } 

读书人网 >C#

热点推荐