17,740
社区成员
发帖
与我相关
我的任务
分享
using System.Runtime.InteropServices;
private const int MF_BYPOSITION = 0x400;
[DllImport("User32")]
private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
[DllImport("User32")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32")]
private static extern int GetMenuItemCount(IntPtr hWnd);
IntPtr hMenu = GetSystemMenu(this.Handle, false);
int menuItemCount = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);
#region "Disable the 'X'"
protected override CreateParams CreateParams
{
get {
CreateParams cp = base.CreateParams;
const int CS_NOCLOSE = 0x200;
cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
return cp;
}
}
#endregion
#Region "Disable the 'X'"
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
Const CS_NOCLOSE As Integer = &H200
cp.ClassStyle = cp.ClassStyle Or CS_NOCLOSE
Return cp
End Get
End Property
#End Region
#region "Disable the 'X'"
protected override CreateParams CreateParams
{
get {
CreateParams cp = base.CreateParams;
const int CS_NOCLOSE = 0x200;
cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
return cp;
}
}
#endregion
[VB.NET]
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_CLOSE As Integer = &HF060
If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32() = SC_CLOSE Then
Return
End If
MyBase.WndProc(m)
End Sub
[C#]
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE)
{
return;
}
base.WndProc (ref m);
}