这个,不大可能不过你可以在closeing事件中把事件e.Cancel=true;这样可以保证不关闭
解决方案 »
- WINDOWS窗体应用程序与WPF应用程序有啥区别?
- 如何用C#修改第三方程序的FormBorderStyle的属性
- 急求 C#在线考试系统视频教程
- 如何遍历(全选)动态输出表格的checkbox?
- 关于读取类中的属性
- 急!!编译时出现的错误!
- 我读文本文件,里面有汉字和数字的组合。我想一行一行的读出来,可读出来的是乱码(试了很多方法)。。帮帮忙啊。。急。。
- 一个编程新手的问题,请高手们给解决一下
- C# 汇总合计算数据代码问题
- 感动“非典”,希望大家群策群力,研究一下,我们程序员在这个时候应该做些什么?
- SOS!多帧gif图片处理 多帧就是哪种能动的gif ,我要放大和缩小,但我处理后就只是单帧了即不能动了
- C#读取XML文档的问题
{
e.Cancel=true; }
//**************************************
// Name: Disable Form Close Button
// Description:This code is used to disable the "X" form button (that one top right) in a form
// By: Claudio Di Flumeri
//
//
// Inputs:The Handle of the form
//
// Returns:None
//
//Assumes:None
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.Planet-Source-Code.com/xq/ASP/txtCodeId.774/lngWId.10/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Long) As IntPtr
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As IntPtr) As Integer
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As IntPtr) As Boolean
// '
Private Const MF_BYPOSITION = &H400
Private Const MF_REMOVE = &H1000
Private Const MF_DISABLED = &H2
// '
Public Sub DisableCloseButton(ByVal hwnd As IntPtr)
Dim hMenu As IntPtr
Dim menuItemCount As Integer
// '
'Obtain the handle to the form's system
// menu
hMenu = GetSystemMenu(hwnd, False)
// '
// 'Obtain the number of items in the menu
menuItemCount = GetMenuItemCount(hMenu)
// '
'Remove the system menu Close menu item.
//
// 'The menu item is 0-based, so the last
// 'item on the menu is menuItemCount - 1
Call RemoveMenu(hMenu, menuItemCount - 1, _
MF_DISABLED Or MF_BYPOSITION)
// '
// 'Remove the system menu separator line
Call RemoveMenu(hMenu, menuItemCount - 2, _
MF_DISABLED Or MF_BYPOSITION)
// '
// 'Force a redraw of the menu. This
// 'refreshes the titlebar, dimming the X
Call DrawMenuBar(hwnd)
End Sub
// '
// '
'------------------- USAGE -------------
// ------
// 'Put this in the Load Event of a Form
// '
DisableCloseButton(Me.Handle)
HWND m_hWnd=GetSystemMenu(this->Handle,false); //关闭按钮
EnableMenuItem(m_hWnd,SC_CLOSE,MF_GRAYED);
==============================
private void yourform_Load(object sender, System.EventArgs e)
{
int lSysMenu;
const int MF_BYPOSITION = 1024;
lSysMenu = WinApi.GetSystemMenu(this.Handle.ToInt32(), 0);
WinApi.RemoveMenu(lSysMenu, 6, MF_BYPOSITION);
//WinApi.RemoveMenu(lSysMenu, 5, MF_BYPOSITION);
}
=====================
public class WinApi
{
[DllImport("User32.dll")]
public static extern int GetSystemMenu(int hWnd, int bRevert);
[DllImport("User32.dll")]
public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);
}
switch(m.Message)
{
case WM_CLOSE://好像是这个,如果不行就试试WM_DESTORY什么的。
{
break;
}
default:
{
base.WndProc(ref m);
break;
}
}