VB.NET關(guān)閉當前窗體me.close()
十載的頭屯河網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都全網(wǎng)營銷的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整頭屯河建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。成都創(chuàng)新互聯(lián)從事“頭屯河網(wǎng)站設(shè)計”,“頭屯河網(wǎng)站推廣”以來,每個客戶項目都認真落實執(zhí)行。
其它窗體用:窗體名.close(),例如:form2.close()
設(shè)置ControlBox為False是可以的,不過全部按鈕都會消失(包括最小化,最大化)
用API可以單獨把關(guān)閉按鈕干掉……
'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
可以,屬性controlBox 為false可以去掉三個按鈕,另外還有maximize,minimize 可以分別控制最大化和最小化按鈕的顯示。
1、如果上一個窗體是程序的主窗體(默認是程序的第一個窗體),
則不能關(guān)閉這個窗體,只能隱藏(Me.Hide())這個窗體,否則整
個程序就被關(guān)掉了。
2、如果上一個窗體不是程序的主窗體,可以用Me.Close()
關(guān)閉。
首先這個應(yīng)該放在 FormClosing 事件中。
其次,因為你 Else 之后沒有忽略窗體關(guān)閉的請求。
應(yīng)該再加一句 e.Cancel = True,表示告訴系統(tǒng),我取消關(guān)閉窗體這個操作了。