Přikládám ještě vb6 to vb.Net pokus :
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal revert As Integer) As Integer
Private Declare Function EnableMenuItem Lib "user32" (ByVal menu As Integer, ByVal ideEnableItem As Integer, ByVal enable As Integer) As Integer
Private Const SC_CLOSE As Integer = &HF060
Private Const MF_BYCOMMAND As Integer = &H0
Private Const MF_GRAYED As Integer = &H1
Private Const MF_ENABLED As Integer = &H0
Private _FormCloseButtonDisabled As Boolean
Friend Property FormCloseButtonDisabled() As Boolean
Get
Return _FormCloseButtonDisabled
End Get
Set(ByVal value As Boolean)
_FormCloseButtonDisabled = value
Select Case EnableMenuItem(GetSystemMenu(Me.Handle.ToInt32, 0), SC_CLOSE, IIf(value, MF_BYCOMMAND Or MF_GRAYED, MF_BYCOMMAND))
Case MF_ENABLED
Case MF_GRAYED
Case &HFFFFFFFF
Throw New Exception("The Close menu item does not exist.")
Case Else
End Select
End Set
End Property Tady lze zrušit zavření (Form1) pomocí Alt+F4 :
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If e.CloseReason = CloseReason.UserClosing Then e.Cancel = FormCloseButtonDisabled
End Sub Tlačítko (Button1) na testování:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
FormCloseButtonDisabled = Not FormCloseButtonDisabled
End Sub Jinak?
|