关于VB窗体的问题
4个回答
展开全部
1)把controlBox设置为False,可以使最大化、最小化、关闭按钮不可见。
2)如果想使关闭按钮失效,而不影响最大化、最小化,可以使用下列代码:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = True
End If
End Sub
这时,最好在窗体上添加一个关闭按钮(不然只能通过结束进程来关闭窗体了),在按钮代码中加上:
Private Sub Command1_Click()
Unload Me
End Sub
由于这种方式在关闭窗体时,QueryUnload事件中的UnloadMode参数会是1,所以不会被屏蔽。
3)如果要使关闭按钮失效或不可见,而不影响最大最小化的话,就只好用API了,抄来一段代码修改一下:
Option Explicit
'Menu item constants.
Private Const SC_CLOSE As Long = &HF060&
'SetMenuItemInfo fMask constants.
Private Const MIIM_STATE As Long = &H1&
Private Const MIIM_ID As Long = &H2&
'SetMenuItemInfo fState constants.
Private Const MFS_GRAYED As Long = &H3&
Private Const MFS_CHECKED As Long = &H8&
'SendMessage constants.
Private Const WM_NCACTIVATE As Long = &H86
'User-defined Types.
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
'Declarations.
Private Declare Function GetSystemMenu Lib "user32" ( _
ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias _
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias _
"SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
' Private Declare Function SendMessage Lib "user32" Alias _
' "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
' ByVal wParam As Long, lParam As Any) As Long
'Application-specific constants and variables.
Private Const xSC_CLOSE As Long = -10
Private Const SwapID As Long = 1
Private Const ResetID As Long = 2
Private hMenu As Long
Private MII As MENUITEMINFO
Private Function SetId(Action As Long) As Long
Dim MenuID As Long
Dim Ret As Long
MenuID = MII.wID
If MII.fState = (MII.fState Or MFS_GRAYED) Then
If Action = SwapID Then
MII.wID = SC_CLOSE
Else
MII.wID = xSC_CLOSE
End If
Else
If Action = SwapID Then
MII.wID = xSC_CLOSE
Else
MII.wID = SC_CLOSE
End If
End If
MII.fMask = MIIM_ID
Ret = SetMenuItemInfo(hMenu, MenuID, False, MII)
If Ret = 0 Then
MII.wID = MenuID
End If
SetId = Ret
End Function
Private Sub Form_Load()
Dim Ret As Long
hMenu = GetSystemMenu(Me.hwnd, 0)
MII.cbSize = Len(MII)
MII.dwTypeData = String(80, 0)
MII.cch = Len(MII.dwTypeData)
MII.fMask = MIIM_STATE
MII.wID = SC_CLOSE
MII.fState = (MII.fState Or MFS_GRAYED)
MII.fMask = MIIM_STATE
Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
2)如果想使关闭按钮失效,而不影响最大化、最小化,可以使用下列代码:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = True
End If
End Sub
这时,最好在窗体上添加一个关闭按钮(不然只能通过结束进程来关闭窗体了),在按钮代码中加上:
Private Sub Command1_Click()
Unload Me
End Sub
由于这种方式在关闭窗体时,QueryUnload事件中的UnloadMode参数会是1,所以不会被屏蔽。
3)如果要使关闭按钮失效或不可见,而不影响最大最小化的话,就只好用API了,抄来一段代码修改一下:
Option Explicit
'Menu item constants.
Private Const SC_CLOSE As Long = &HF060&
'SetMenuItemInfo fMask constants.
Private Const MIIM_STATE As Long = &H1&
Private Const MIIM_ID As Long = &H2&
'SetMenuItemInfo fState constants.
Private Const MFS_GRAYED As Long = &H3&
Private Const MFS_CHECKED As Long = &H8&
'SendMessage constants.
Private Const WM_NCACTIVATE As Long = &H86
'User-defined Types.
Private Type MENUITEMINFO
cbSize As Long
fMask As Long
fType As Long
fState As Long
wID As Long
hSubMenu As Long
hbmpChecked As Long
hbmpUnchecked As Long
dwItemData As Long
dwTypeData As String
cch As Long
End Type
'Declarations.
Private Declare Function GetSystemMenu Lib "user32" ( _
ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias _
"GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
ByVal b As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias _
"SetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, _
ByVal bool As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
' Private Declare Function SendMessage Lib "user32" Alias _
' "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
' ByVal wParam As Long, lParam As Any) As Long
'Application-specific constants and variables.
Private Const xSC_CLOSE As Long = -10
Private Const SwapID As Long = 1
Private Const ResetID As Long = 2
Private hMenu As Long
Private MII As MENUITEMINFO
Private Function SetId(Action As Long) As Long
Dim MenuID As Long
Dim Ret As Long
MenuID = MII.wID
If MII.fState = (MII.fState Or MFS_GRAYED) Then
If Action = SwapID Then
MII.wID = SC_CLOSE
Else
MII.wID = xSC_CLOSE
End If
Else
If Action = SwapID Then
MII.wID = xSC_CLOSE
Else
MII.wID = SC_CLOSE
End If
End If
MII.fMask = MIIM_ID
Ret = SetMenuItemInfo(hMenu, MenuID, False, MII)
If Ret = 0 Then
MII.wID = MenuID
End If
SetId = Ret
End Function
Private Sub Form_Load()
Dim Ret As Long
hMenu = GetSystemMenu(Me.hwnd, 0)
MII.cbSize = Len(MII)
MII.dwTypeData = String(80, 0)
MII.cch = Len(MII.dwTypeData)
MII.fMask = MIIM_STATE
MII.wID = SC_CLOSE
MII.fState = (MII.fState Or MFS_GRAYED)
MII.fMask = MIIM_STATE
Ret = SetMenuItemInfo(hMenu, MII.wID, False, MII)
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
参考资料: http://support.microsoft.com/kb/q184686/
展开全部
在窗体属性里改:
方法一:将controlBox 属性设为False
方法二:将 BorderStyle 属性设为0-none,即无窗口边框,这时,你可以自己画边框(通过其picture属性设置进去),并在右上角放一个按钮,设置
caption="X";
定义其功能
Private Sub Command1_Click()
if .... then
end
else ...
End Sub
方法一:将controlBox 属性设为False
方法二:将 BorderStyle 属性设为0-none,即无窗口边框,这时,你可以自己画边框(通过其picture属性设置进去),并在右上角放一个按钮,设置
caption="X";
定义其功能
Private Sub Command1_Click()
if .... then
end
else ...
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Form属性中有个controlBox属性,将他设置为FALSE就可以了!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哪要那么麻烦
下面的代码就可以搞定:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert 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 Sub Form_Load()
RemoveMenu GetSystemMenu(Me.hwnd, 0), &HF060, &H1000&
End Sub
下面的代码就可以搞定:
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert 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 Sub Form_Load()
RemoveMenu GetSystemMenu(Me.hwnd, 0), &HF060, &H1000&
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询