Hey people, here is a question that is troubling me from quite a long time.
I want to diable the (x) button on form_load event, to prevent user from directly closing the application.
How may I achieve this ?
Go to FormClosing event of the form and add e.Cancel=True.
Edited by Fame95
@Fame95: I Am aware of this. But I Want user to see (x) button disabled when form is loaded.
@Fame95: That Was of No Help.
Appreciate your effort though.
Private Const CP_NOCLOSE_BUTTON As Integer = &H200 Protected Overrides ReadOnly Property CreateParams() As CreateParams Get Dim myCp As CreateParams = MyBase.CreateParams myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON Return myCp End Get End Property
That should work, put into the Form's code you wish to disable under:
Public Class Form
Credit goes to @Fame95 His answer was correct.
Edited by Doogledude123: Gave credit where credit was deserved
you may remove that button on the form's property window, find ControlBox and set to False.
If you want to insist on doing it in run time use
Me.ControlBox = False or for C#
this.ControlBox = false;
@tinstaafl Im assuming he wants to keep Minimize and Maximize, thats what my code does.
Be advised that setting the class style to CS_NOCLOSE (named CP_NOCLOSE_BUTTON in Doogledude's example) will also prevent Alt-F4 from closing the window. You can achieve the same effect while retaining Alt-F4 closure by PInvoking the RemoveMenu function.
Private Const MF_BYCOMMAND As Integer = 0 <DllImport("User32")> _ Private Shared Function RemoveMenu(ByVal hMenu As IntPtr, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer End Function <DllImport("User32")> _ Private Shared Function GetSystemMenu(ByVal hWnd As IntPtr, ByVal bRevert As Boolean) As IntPtr End Function Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim hMenu As IntPtr = GetSystemMenu(Me.Handle, False) RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND) End Sub
Thanks for contributing to this discussion. I learned a lot from you people.
The smart answer i will go with Me.ControlBox = False. Because it uses inbuilt function and saved my time.
Despite the fact that it does not provide maximize and minimize button, it can be minimized from startbar. And Its Cool
Special Thanks to tinstaafl.
And Kudos to all.
i have these GNU macro:
#if defined __GNUC__ #define EVENT [[gnu::weak]] #elif defined __clang__ #define EVENT [[llvm::weak]] #endif #define IS_EVENT_DEFINED(sym) (static_cast<bool>(sym))
these macro works fine. and help me test if ...
APLX is a very complete implementation of the APL programming language from MicroAPL. The company stopped producing it in 2016 and it has been taken over by Dyalog. While Dyalog ...
Try Dim Adapter As New OleDbDataAdapter Dim Command As New OleDbCommand Dim xFrom As String = dtpFrom.Value.ToString.Substring(0, dtpFrom.Value.ToString.IndexOf(" ")) Dim xTo As String = dtpTo.Value.ToString.Substring(0, dtpTo.Value.ToString.IndexOf(" ")) sqlQuery = MainQuery ...