大学IT网 - 最懂大学生的IT学习网站! QQ资料交流群:367606806
当前位置:大学IT网 > C#技巧 > c# 使用api函数 ShowWindowAsync 控制窗体

c# 使用api函数 ShowWindowAsync 控制窗体(2)

关键词:窗体函数apiShowWindowAsync  阅读(1040) 赞(19)

[摘要]本文是对c# 使用api函数 ShowWindowAsync 控制窗体的讲解,对学习C#编程技术有所帮助,与大家分享。

[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);

}

}

}

«上一页12下一页»


相关评论