首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2012-10-21 
C# 想让子窗体随主窗体移动而移动就在 private void button1_Click(object sender, EventArgs e){Form f

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

热点排行