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

怎么实现鼠标拖动一个控件移动

2012-08-16 
如何实现鼠标拖动一个控件移动?Window我们可以用DragMove()函数实现,如果是控件呢?怎么实现拖动?[解决办法

如何实现鼠标拖动一个控件移动?
Window我们可以用DragMove()函数实现,如果是控件呢?怎么实现拖动?

[解决办法]
用鼠标的坐标赋值给控件的location来实现
[解决办法]
点击按钮时监控鼠标,鼠标移动到哪里就跟着移动。

按钮释放,停止移动。
[解决办法]
MouseDown中置标记isdown=true,MouseMove中,如果isdown,则根据鼠标位置控制控件的left和top,MouseUp事件中,isdown=false
[解决办法]
拖动一个按钮

定义

C# code
private System.Windows.Forms.Button button1;        private bool Mousedown = false;  //鼠标按下为true        private int CurX = 0,CurY = 0;
[解决办法]
C# code
      [DllImport("user32.dll")]        static extern bool ReleaseCapture();        [DllImport("user32.dll", CharSet = CharSet.Auto)]        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);        private readonly UInt32 WM_SYSCOMMAND = 0x112;        private readonly UInt32 SC_MOVE = 0xF010;        private readonly UInt32 HTCAPTION = 2;                private void button1_Click(object sender, EventArgs e)        {            MessageBox.Show("1");        }        private void button1_MouseMove(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)            {                ReleaseCapture();                SendMessage(button1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);            }        }
[解决办法]
探讨

C# code
[DllImport("user32.dll")]
static extern bool ReleaseCapture();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, U……

[解决办法]
http://download.csdn.net/detail/wangyue4/2874530
c# 实现任意控件的拖拽
我自己写的
[解决办法]
探讨

http://download.csdn.net/detail/wangyue4/2874530
c# 实现任意控件的拖拽
我自己写的

热点排行