Window我们可以用DragMove()函数实现,如果是控件呢?怎么实现拖动?
解决方案 »
- win8应用调用web service的enValidateImage,在线等,立马结分。
- 请问为什么ClientSocket.Connect(ServerInfo);运行时会出现 对像没有实例化??
- 这算不算.NET的BUG,老鸟进来说说
- 最难的正则表达式:匹配Url,解决的就给分
- SQl简单问题
- 又来麻烦大家了,关于数据查询的问题/?
- 急,求救,不小心删除了一个文件夹。
- .net与JAVA rsa加密交互
- ValueMember 和 DisplayMember
- 大家好,(在做Web的)用C#怎么保存和读出光标的位置,谢 看内宾:
- Lambda表达式中如何处理闭包?
- 如何计算这道与泛型有关的题,谢谢
private bool Mousedown = false; //鼠标按下为true
private int CurX = 0,CurY = 0;
事件private void button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(Mousedown)
{
//Cursor.Position .X Cursor.Position .Y 是屏幕坐标
//用屏幕坐标减窗口坐标以保持鼠标总是在窗口的原位置.
Point sp = new Point(Cursor.Position.X,Cursor.Position.Y);
Point np = this.PointToClient(sp);
this.button1.Location = new Point(np.X - CurX,np.Y - CurY);//(Cursor.Position .X - CurX,Cursor.Position .Y - CurY);
}
} private void button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
CurX = e.X;//保存鼠标按下是鼠标在窗口的坐标
CurY = e.Y;
Mousedown = true;
this.button1.Capture = true;
} private void button1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
Mousedown = false;
this.button1.Capture = false;
}
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# 实现任意控件的拖拽
我自己写的