C#如何禁用Form窗口的最大化按钮

实际项目开发过程中,我们可能需要将Form窗口的最大化按钮禁用掉。
1。设定系统菜单
首先在窗体类中声明:
public class Form1 : System.Windows.Forms.Form
{
[DllImport("user32.dll",EntryPoint="GetSystemMenu")] //导入API函数
extern static System.IntPtr GetSystemMenu(System.IntPtr hWnd , System.IntPtr bRevert);

[DllImport("user32.dll",EntryPoint="RemoveMenu")]
extern static int RemoveMenu (IntPtr hMenu, int nPos, int flags);
static int MF_BYPOSITION = 0x400;
static int MF_REMOVE = 0x1000;

public Form1()//构造函数
{
InitializeComponent();
RemoveMenu(GetSystemMenu(Handle,IntPtr.Zero),0,MF_BYPOSITION|MF_REMOVE);
}
}

2。窗体属性设置
将 窗体的 FormBorderStyle 属性设为 FixedSingle。//改变窗体风格,使之不能用鼠标改变大小
MaximizeBox 属性设为 false//禁止使用最大化按钮

posted @ 2011-12-05 16:28  大佛张  阅读(1390)  评论(0编辑  收藏  举报