C# Winform 讓整個窗口都可以拖動
更新時間:2011年05月14日 16:02:26 作者:
Windows 的 API 果然強(qiáng)大啊.以前要實(shí)現(xiàn)全窗口拖動, 要寫鼠標(biāo)按下和抬起事件, 很是麻煩, 偶爾還會出現(xiàn) BUG
今天在網(wǎng)上查一些資料的時候, 無意中發(fā)現(xiàn)另一種辦法, 非常方便, 調(diào)用系統(tǒng)的 API 來實(shí)現(xiàn)的, 效果也很好. 趕緊收藏了~
[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 void frmMain_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x0112, 0xF012, 0);
}
復(fù)制代碼 代碼如下:
[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 void frmMain_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, 0x0112, 0xF012, 0);
}
相關(guān)文章
C# LINQ查詢表達(dá)式及對應(yīng)LAMBDA表達(dá)式的用法
這篇文章主要介紹了C# LINQ查詢表達(dá)式及對應(yīng)LAMBDA表達(dá)式的用法,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-04-04

c# SQLHelper(for winForm)實(shí)現(xiàn)代碼
數(shù)據(jù)連接池c# SQLHelper 實(shí)現(xiàn)代碼
2009-02-02 
newtonsoft.json解析天氣數(shù)據(jù)出錯解決方法
這篇文章主要介紹了NewtonSoft.JSon解析天氣數(shù)據(jù)時出錯的解決方法,需要的朋友可以參考下
2014-02-02 
c#生成站點(diǎn)地圖(SiteMapPath)文件示例程序
這篇文章主要介紹了c#生成站點(diǎn)地圖(SiteMapPath)文件的示例,大家參考使用
2013-11-11 
C# 屏蔽關(guān)鍵字的實(shí)現(xiàn)方法
前段時間在公司做了一個論壇屏蔽關(guān)鍵字的功能,我做的比較簡單、實(shí)用~ 現(xiàn)在拿出來給博友們分享下..也希望大家能頂頂我~
2013-05-05 
C#實(shí)現(xiàn)六大設(shè)計原則之里氏替換原則
這篇文章介紹了C#實(shí)現(xiàn)六大設(shè)計原則之里氏替換原則的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
2022-02-02