在C#中,实现可拖动控件,并显示控件的坐标位置

private   Point   mouse_offset;

private   void   Control_MouseDown(object   sender,System.Windows.Forms.MouseEventArgs   e)
{
            mouse_offset   =   new   Point(-e.X,-e.Y);
}

private   void   Control_MouseMove(object   sender,System.Windows.Forms.MouseEventArgs   e)
{
      if   (e.Button   ==   MouseButtons.Left)
      {
            Point   mousePos   =   Control.MousePosition;
            mousePos.Offset(mouse_offset.X,   mouse_offset.Y);
            ((Control)sender).Location   =   ((Control)sender).Parent.PointToClient(mousePos);
      }

  this.label1.Text ="横坐标:"+mouse_offset.X+"纵坐标"+mouse_offset.Y;
}

posted on 2010-09-25 09:44  程雨轩  阅读(2309)  评论(0编辑  收藏  举报

导航