設(shè)置窗體的text為空,設(shè)置窗體的controlbox屬性為false,設(shè)置窗體的FormBorderStyle 屬性為Sizable,就可以改變窗體大小了,并且可以在任務(wù)欄點擊。
創(chuàng)新互聯(lián)主要從事成都網(wǎng)站設(shè)計、網(wǎng)站制作、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)雙臺子,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
設(shè)置全局變量:
Dim?drag?As?Boolean
Dim?mousex?As?Integer
Dim?mousey?As?Integer
假設(shè)你想拖動的是Panel1控件,以及此控件上的?Label1(用于顯示標(biāo)題)和PictureBox4(用于顯示圖標(biāo)):
Private?Sub?TitleMove_MouseDown(sender?As?Object,?e?As?System.Windows.Forms.MouseEventArgs)?Handles?Panel1.MouseDown,?Label1.MouseDown,?PictureBox4.MouseDown
drag?=?True
mousex?=?Windows.Forms.Cursor.Position.X?-?Me.Left
mousey?=?Windows.Forms.Cursor.Position.Y?-?Me.Top
End?Sub
Private?Sub?TitleMove_MouseMove(sender?As?Object,?e?As?System.Windows.Forms.MouseEventArgs)?Handles?Panel1.MouseMove,?Label1.MouseMove,?PictureBox4.MouseMove
If?drag?Then
Me.Top?=?Windows.Forms.Cursor.Position.Y?-?mousey
Me.Left?=?Windows.Forms.Cursor.Position.X?-?mousex
End?If
End?Sub
Private?Sub?TitleMove_MouseUp(sender?As?Object,?e?As?System.Windows.Forms.MouseEventArgs)?Handles?Panel1.MouseUp,?Label1.MouseUp,?PictureBox4.MouseUp
drag?=?False
End?Sub
調(diào)用系統(tǒng)API使窗體下?lián)碛嘘幱靶Ч?/p>
using System.Runtime.InteropServices;
然后再窗口類的隨便哪個地方加上:
const int CS_DROPSHADOW = 0x20000;
const int GCL_STYLE = (-26);
//聲明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd,int nIndex,int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex);
最后在窗體的構(gòu)造函數(shù)中加上:
SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DROPSHADOW);