怎么实现呢???

解决方案 »

  1.   

    发消息,,用event ,但主窗体移动时发坐标给子窗体
      

  2.   

    网友问我的一个问题:移动一个窗体时如何同时移动另一个窗体?类似winAMP里的效果。其实实现起来也很简单:截获主窗体的WM_MOVE(窗体移动)消息,同时设置附属窗体的位置。代码如下:
    protected override void WndProc(ref   Message m)
              {
                 const int WM_MOVE = 0x3;
                 
                 if (m.Msg == WM_MOVE )
                  {
                     if (frm != null)
                      {
                         frm.Left = this.Left + this.Width;
                         frm.Top = this.Top;
                         return;
                     }
                 }
                 base.WndProc(ref   m);
             }
    frm即附属窗体的对象
      

  3.   

    主窗体的移动是用MouseMove来获取坐标吗?
    但是MouseEventArgs怎么传给Message呢?
      

  4.   

    public partial class Form1 : Form
      {
        Form f2 = new Form2();    public Form1()
        {
          InitializeComponent();
        }    private void Form1_Load(object sender, EventArgs e)
        {
          f2.Show();
        }    protected override void WndProc(ref Message m)
        {
          const int WM_MOVE = 0x3;      if (m.Msg == WM_MOVE)
            f2.Location = new Point(this.Left + this.Width, this.Top);      base.WndProc(ref m);
        }
      }
      

  5.   

    知道为什么了,窗体form1传给from2的坐标是form1上一次的坐标,而不是当前坐标
      

  6.   

    public partial class Form1 : Form
      {
        Form f2 = new Form2();    public Form1()
        {
          InitializeComponent();
        }    private void Form1_Load(object sender, EventArgs e)
        {
          f2.Show();
        }    protected override void WndProc(ref Message m)
        {
          const int WM_MOVE = 0x3;      if (m.Msg == WM_MOVE)
            f2.Location = new Point(this.Left + this.Width, this.Top);      base.WndProc(ref m);
        }
      }
     这个代码form1与form2不能同时移动
    form2拿到的是form1上一次的移动位置奇怪。。
      

  7.   

    form1的事件Move来实现就很容易了。        private void FormQuery_Move(object sender, EventArgs e)
            {
                testForm.Show();
                testForm.Location = new Point(this.Location.X + this.Width, this.Location.Y);
            }
      

  8.   

    public partial class Form1 : Form
        {
            Form f2 = new Form2();
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                f2.Show();
            }      
            private void Form1_Move(object sender, EventArgs e)
            {
                f2.Location = new Point(this.Left + this.Width, this.Top);
            }
            protected override void WndProc(ref Message m)
            {
                const int WM_MOVE = 0x3;            if (m.Msg == WM_MOVE)
                    f2.Location = new Point(this.Left + this.Width, this.Top);            base.WndProc(ref m);
            }    }
    这样就OK了
      

  9.   

    public partial class Form1 : Form
        {
            Form f2 = new Form2();
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                f2.Show();
            }      
            private void Form1_Move(object sender, EventArgs e)
            {
                f2.Location = new Point(this.Location.X + this.Width, this.Location.Y);
            }
    }这样就行了