This tutorial will teach you how to create program that can disable and enable a close button in the windows form using vb.net language.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to
File, click
New Project, and choose
Windows Application.
2. Next, add a GroupBox and two buttons for Disable and Enable Close button named Button1 and Button2 respectively. You must design your interface like this:
3. Now, we will do the coding.
We will create first the enums named Choice and Position to get the Position of closing and the options such as disable or enable the close button.
Enum choice
Disable = 0
Enable = 1
End Enum
Enum Position
rmclose = 6
End Enum
Create also a structure named xPont to get the coordinates.
Structure xPont
Dim x, y As Int64
End Structure
Declare this functions using the user32 library.
Declare Function RemoveMenu Lib "user32" (ByVal menu As Int32, ByVal Pos As Int32, ByVal u As Int32) As Int32
Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Int32, ByVal rseve As Int32) As Int32
Declare Function WindowFromPoint Lib "user32" (ByVal x As Int64, ByVal y As Int64) As Int32
Private Const MF_POSITION As Int32 = &H400
Now, lets code for the Disable Close Button. Have this code below:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim menu As Int64
'disable the close button
menu = GetSystemMenu(Me.Handle.ToInt32, choice.Disable)
RemoveMenu(CInt(menu), Position.rmclose, MF_POSITION)
End Sub
And the enable close button with this:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim menu2 As Int64
'enable the close button
menu2 = GetSystemMenu(Me.Handle.ToInt32, choice.Enable)
RemoveMenu(CInt(menu2), Position.rmclose, MF_POSITION)
End Sub
Download the source code and try it!
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:
[email protected]
Add and Follow me on Facebook:
https://www.facebook.com/donzzsky
Visit and like my page on Facebook at:
https://www.facebook.com/BermzISware