110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace testRunningDrag
{
public partial class Form1 : Form
{
bool AreaChange = false;
Control moveCtrl;
public Form1()
{
InitializeComponent();
}
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern int ReleaseCapture();
private void pic1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(pic1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (this.AreaChange == true)
{
moveCtrl.Width = e.X-pic1.Left;
moveCtrl.Height = e.Y-pic1.Top;
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
//label1.Text = string.Format("{0},{1} {2},{3}", e.X.ToString(), e.Y.ToString(), pic1.Left + pic1.Width, pic1.Top + pic1.Height);
if (e.X - pic1.Left - pic1.Width < 10 && e.Y - pic1.Top - pic1.Height < 10)
{
AreaChange = true;
moveCtrl = pic1;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
AreaChange = false;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace testRunningDrag
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern int ReleaseCapture();
private void pic1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(pic1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}
}