我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net禁用关闭按钮 excel关闭按钮

vb禁止窗口关闭命令

1、窗体属性ControlBox=False则不显示关闭、最大化、最小化按钮

为东山等地区用户提供了全套网页设计制作服务,及东山网站建设行业解决方案。主营业务为成都网站设计、网站建设、东山网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

2、如果还想保留最大化、最小化按钮,仅仅不允许关窗口,可以

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Cancel = True

End Sub

在vb里,如何将窗口右上方的“关闭”按钮设为禁用??

复制以下代码就可以实现将窗口右上方的“关闭”按钮设为禁用

Option Explicit

Private Declare Function GetSystemMenu Lib "user32"_

(ByVal hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function GetMenuItemCount Lib "user32"_

(ByVal hMenu As Long) As Long

Private Declare Function RemoveMenu Lib "user32"_

(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Private Declare Function DrawMenuBar Lib "user32"_

(ByVal hwnd As Long) As Long

Private Const MF_BYPOSITION = H400

Private Const MF_REMOVE = H1000

Private Sub DisableX()

Dim hMenu As Long

Dim nCount As Long

hMenu = GetSystemMenu(Me.hWnd, 0)

nCount = GetMenuItemCount(hMenu)

'Get rid of the Close menu and its separator

Call RemoveMenu(hMenu, nCount - 1, MF_REMOVE Or MF_BYPOSITION)

Call RemoveMenu(hMenu, nCount - 2, MF_REMOVE Or MF_BYPOSITION)

'Make sure the screen updates

'our change DrawMenuBar Me.hWnd

End Sub

Private Sub Form_Load()

DisableX

End Sub

Private Sub Form_Click()

'We need a way out, since the X button'doesn't work :-)

Unload Me

End Sub

VB2008 如何取消窗体的关闭按钮

设置ControlBox为False是可以的,不过全部按钮都会消失(包括最小化,最大化)

用API可以单独把关闭按钮干掉……

'VB.NET Code

Public Class Form1

Private Declare Function GetSystemMenu Lib "User32 " (ByVal hwnd As Integer, ByVal bRevert As Long) As Integer

Private Declare Function RemoveMenu Lib "User32 " (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer

Private Declare Function DrawMenuBar Lib "User32 " (ByVal hwnd As Integer) As Integer

Private Declare Function GetMenuItemCount Lib "User32 " (ByVal hMenu As Integer) As Integer

Private Const MF_BYPOSITION = H400

Private Const MF_DISABLED = H2

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim hMenu As Integer, nCount As Integer

hMenu = GetSystemMenu(Me.Handle.ToInt32, 0)

nCount = GetMenuItemCount(hMenu)

'Debug.Print(nCount)

Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)

DrawMenuBar(Me.Handle.ToInt32)

End Sub

End Class

'VB6 code =============================================================

Private Declare Function GetSystemMenu Lib "User32 " (ByVal hwnd As Long, ByVal bRevert As Long) As Integer

Private Declare Function RemoveMenu Lib "User32 " (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long

Private Declare Function DrawMenuBar Lib "User32 " (ByVal hwnd As Long) As Long

Private Declare Function GetMenuItemCount Lib "User32 " (ByVal hMenu As Long) As Long

Private Const MF_BYPOSITION = H400

Private Const MF_DISABLED = H2

Private Sub Form1_Load()

Dim hMenu As Long, nCount As Long

hMenu = GetSystemMenu(Me.hWnd, 0)

nCount = GetMenuItemCount(hMenu)

'Debug.Print nCount

Call RemoveMenu(hMenu, nCount - 1, MF_DISABLED Or MF_BYPOSITION)

DrawMenuBar Me.hWnd

End Sub

vb.net中 如何将窗体上的关闭按钮禁用 也就是变灰啊?

FormBorderStyle选为None,没有标题栏

form 的 controlbox 属性为false

VB如何恢复被ModifyMenu禁用窗体关闭按钮

'禁用关闭菜单

ModifyMenu GetSystemMenu(Me.hwnd, 0), SC_CLOSE, MF_GRAYED, 7, "不允许关闭"

将菜单ID为SC_CLOSE设置为菜单索引7的菜单项,并禁用关闭菜单

'恢复禁用的关闭菜单

ModifyMenu GetSystemMenu(Me.hwnd, 0), 7, MF_ENABLED, SC_CLOSE, "允许关闭"

将菜单的索引为7的菜单项重新设置回菜单ID,并启用关闭菜单


分享名称:vb.net禁用关闭按钮 excel关闭按钮
地址分享:http://shouzuofang.com/article/hhpeoh.html

其他资讯