拖動無邊框窗體

2021-09-08 08:31:57 字數 3323 閱讀 7051

frm_main.cs

1

using system;

2using system.collections.generic;

3using system.componentmodel;

4using system.data;

5using system.drawing;

6using system.linq;

7using system.text;

8using system.windows.forms;

9using system.runtime.interopservices;

1011

namespace dragnoframeform

12 19

20#region 本程式中用到的api函式

21 [dllimport("

user32.dll

")]22

public

static

extern

bool releasecapture();//

用來釋放被當前執行緒中某個視窗捕獲的游標

23 [dllimport("

user32.dll

")]24

public

static

extern

bool sendmessage(intptr hwdn,int wmsg,int mparam,int lparam);//

向指定的窗體傳送windows訊息

25#endregion

2627

#region 本程式中需要宣告的變數

28public

const

int wm_syscommand = 0x0112;//

該變數表示將向windows傳送的訊息型別

29public

const

int sc_move = 0xf010;//

該變數表示傳送訊息的附加訊息

30public

const

int htcaption = 0x0002;//

該變數表示傳送訊息的附加訊息

31#endregion

3233

private

退出本程式

36 }

3738

private

void frm_main_mousedown(object sender, mouseeventargs e)

39

43 }

44 }

frm_main.designer.cs

1

namespace dragnoframeform

2 20

base.dispose(disposing);

21 }

2223

#region windows 窗體設計器生成的**

2425

///26

///設計器支援所需的方法 - 不要

27///

使用**編輯器修改此方法的內容。

28///

29private

void initializecomponent()

30 );

41this.contextmenustrip1.name = "

contextmenustrip1

";42

this.contextmenustrip1.size = new system.drawing.size(101, 26);

43//

44//

exitcontext

45//

46this.exitcontext.name = "

exitcontext

";47

this.exitcontext.size = new system.drawing.size(100, 22);

48this.exitcontext.text = "

退出";

49this.exitcontext.click += new system.eventhandler(this.exitcontext_click);

50//

51//

frm_main

52//

53this.autoscaledimensions = new system.drawing.sizef(6f, 12f);

54this.autoscalemode = system.windows.forms.autoscalemode.font;

55this.backgroundimage = global::dragnoframeform.properties.resources._04;

56this.backgroundimagelayout = system.windows.forms.imagelayout.stretch;

57this.clientsize = new system.drawing.size(320, 228);

58this.contextmenustrip = this.contextmenustrip1;

59this.formborderstyle = system.windows.forms.formborderstyle.none;

60this.name = "

frm_main

";61

this.startposition = system.windows.forms.formstartposition.centerscreen;

62this.text = "

拖動無邊框窗體

";63

this.mousedown += new system.windows.forms.mouseeventhandler(this.frm_main_mousedown);

64this.contextmenustrip1.resumelayout(false);

65this.resumelayout(false);

6667 }

6869

#endregion

7071

private system.windows.forms.contextmenustrip contextmenustrip1;

72private system.windows.forms.toolstripmenuitem exitcontext;

73 }

74 }

墨明棋妙

出處:

C Winform 無邊框拖動窗體

一 無邊框拖動窗體 當設定窗體的formboderstyle為null時,系統自帶的窗體拖拽屬性就失效了,需要自己寫這一部分。在這個工具裡博主曹勇panel控制項當作窗體的頭部,因此實現窗體拖拽也就是實現拖拽panel時窗體位置發生變化,如下 首先引入系統api dllimport user32.d...

c 無邊框拖動

static class safenativemethods protected override void onmousedown mousebuttoneventargs e 拖動protected override void wndproc ref message m return case ...

無邊框窗體拖動和改變大小

const int htleft 10 const int htright 11 const int httop 12 const int httopleft 13 const int httopright 14 const int htbottom 15 const int htbottomlef...