標籤:style io ar os sp for on bs ad
private void BaseCForm_Load(object sender, EventArgs e)
{
DrawStyle();
this.panel1.MouseDown += new MouseEventHandler(panel1_MouseDown);
this.panel1.MouseUp += new MouseEventHandler(panel1_MouseUp);
this.panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y);
leftFlag = true;
}
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
leftFlag = false;
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y);
if (sender is Panel)
{
((System.Windows.Forms.Panel)sender).Parent.Location = mouseSet;
}
}
}
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
private const int WM_SYSCOMMAND = 0x0112;//點擊視窗左上方那個表徵圖時的系統資訊
private const int WM_MOVING = 0x216;//滑鼠移動訊息
private const int SC_MOVE = 0xF010;//移動資訊
private const int HTCAPTION = 0x0002;//表示滑鼠在視窗標題列時的系統資訊
private const int WM_NCHITTEST = 0x84;//滑鼠在表單客戶區(除了標題列和邊框以外的部分)時發送的訊息
private const int HTCLIENT = 0x1;//表示滑鼠在視窗客戶區的系統訊息
private const int SC_MAXIMIZE = 0xF030;//最大化資訊
private const int SC_MINIMIZE = 0xF020;//最小化資訊
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_MOVING: //如果滑鼠移
base.WndProc(ref m);//調用基類的視窗過程——WndProc方法處理這個訊息
if (m.Result == (IntPtr)HTCLIENT)//如果返回的是HTCLIENT
{
m.Result = (IntPtr)HTCAPTION;//把它改為HTCAPTION
return;//直接返回退出方法
}
break;
}
base.WndProc(ref m);//如果不是滑鼠移動或單擊訊息就調用基類的視窗過程進行處理
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
base.OnMouseMove(e);
}
c#表單去掉borderstyle進行拖動