Die folgende Funktion deaktiviert den x-Button des Formulares.
Dies kann recht nützlich sein um ein unbeabsichtigtes schliessen des Formulares zu verhindern.
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
Public Const iPOSITION = &HF060&
Public Const iFLAGS = &H0&
Function NoFormCloseButton(ByVal iHWND As Integer) As Integer
Dim WindowSystemMenu As Integer = GetSystemMenu(iHWND, False)
Return RemoveMenu(WindowSystemMenu, iPOSITION, iFLAGS)
End Function
'Auf der funktion im Activated Event des Formulares
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
NoFormCloseButton(ActiveForm.Handle().ToInt32())
End Sub
Kommentare zum Snippet