国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

c# 使用api函數 ShowWindowAsync 控制窗體

2019-11-17 02:51:28
字體:
來源:轉載
供稿:網友
c# 使用api函數 ShowWindowAsync 控制窗體

1.需要匯入System.Runtime.InteropServices命名空間

2.宣告 ShowWindowAsync 函數

[DllImport("user32.dll")]

PRivatestaticexternboolShowWindowAsync(

IntPtrhWnd,

intnCmdShow

);

3.宣告 ShowWindow函數

[DllImport("user32.dll")]

publicstaticexternintShowWindow(

inthwnd,

intnCmdShow

);

4.宣告API常數定義

//API 常數定義

privateconstintSW_HIDE = 0;

privateconstintSW_NORMAL = 1;

privateconstintSW_MAXIMIZE = 3;

privateconstintSW_SHOWNOACTIVATE = 4;

privateconstintSW_SHOW = 5;

privateconstintSW_MINIMIZE = 6;

privateconstintSW_RESTORE = 9;

privateconstintSW_SHOWDEFAULT = 10;

5.上述函數功能相同,都是用來設定視窗大小,不同的是宣告的型態不一樣需轉型。

ShowWindowAsync(this.Handle, SW_MINIMIZE);

ShowWindow((int)this.Handle, SW_MINIMIZE);

6.若是把int改成IntPtr,使用ShowWindow就不用轉型,所以在宣告時就可以考慮資料型態,必免轉型所耗的資源。

[DllImport("user32.dll")]

publicstaticexternintShowWindow(

inthwnd,

intnCmdShow

);

C#完整範例

usingSystem;

usingSystem.Windows.Forms;

usingSystem.Runtime.InteropServices;

namespaceCS_WindowsResize

{

publicpartialclassForm1:Form

{

publicForm1()

{

InitializeComponent();

}

//API 常數定義

privateconstintSW_HIDE = 0;

privateconstintSW_NORMAL = 1;

privateconstintSW_MAXIMIZE = 3;

privateconstintSW_SHOWNOACTIVATE = 4;

privateconstintSW_SHOW = 5;

privateconstintSW_MINIMIZE = 6;

privateconstintSW_RESTORE = 9;

privateconstintSW_SHOWDEFAULT = 10;

[DllImport("user32.dll")]

privatestaticexternboolShowWindowAsync(

IntPtrhWnd,

intnCmdShow

);

[DllImport("user32.dll")]

publicstaticexternintShowWindow(

inthwnd,

intnCmdShow

);

privatevoidbutton1_Click(objectsender,EventArgse)

{

//最小化

ShowWindowAsync(this.Handle, SW_MINIMIZE);

}

privatevoidbutton2_Click(objectsender,EventArgse)

{

//最大化

ShowWindowAsync(this.Handle, SW_MAXIMIZE);

}

privatevoidbutton3_Click(objectsender,EventArgse)

{

//還原

ShowWindowAsync(this.Handle, SW_RESTORE);

}

privatevoidbutton4_Click(objectsender,EventArgse)

{

//最小化

ShowWindow((int)this.Handle, SW_MINIMIZE);

}

privatevoidbutton5_Click(objectsender,EventArgse)

{

//最大化

ShowWindow((int)this.Handle, SW_MAXIMIZE);

}

privatevoidbutton6_Click(objectsender,EventArgse)

{

//還原

ShowWindow((int)this.Handle, SW_RESTORE);

}

}

}

轉載自:http://www.dotblogs.com.tw/yc421206/archive/2009/07/06/9140.aspx


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 井研县| 西昌市| 乐陵市| 河北区| 天长市| 昌邑市| 嘉定区| 女性| 五指山市| 浠水县| 梧州市| 和政县| 沽源县| 临沂市| 营口市| 邹平县| 太白县| 那曲县| 丹江口市| 汝南县| 淅川县| 新建县| 酉阳| 微山县| 崇信县| 蚌埠市| 凌海市| 宁津县| 武宣县| 永济市| 武功县| 大庆市| 景洪市| 环江| 涿州市| 华亭县| 车致| 车致| 宁武县| 长岛县| 东兴市|