Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Does anyone know how to override or disable the Exit button ("X") on the top right hand corner of a windows form?? The maximize and minimize controls can be disable though the property builder, but the Exit button cannot. I'm working with multiple forms, and by default when the "X" button is clicked, the form is disposed, and thus, lost forever!!!!!!!

 

---Matt

Posted

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       e.Cancel = True
   End Sub

 

This will not allow you to close the form at all, unless you use the End keyword or create a special function that is called from Form1_Closing.

Posted
If you are disabling the min and max as well and don't want them to have the ability to hit the x button you can set the "controlbox" to false in the properties and you won't see those at all
Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted

Something I have used is using the example by Celeron and a form level variable called mblnFromExitButton

 

Private Sub frmLapTimes_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
       If mblnFromExitButton = False Then
           e.Cancel = True
       End If
   End Sub

 

Then in your exit button, just set the mblnFromExitButton to true.

"Nobody knows what I do until I stop doing it."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...