• 0

Prevent application from being closed


Question

Hey people, I'm working on a custom shell using Visual Basic .NET, and I was wondering if there is a way I can prevent the application from being closed with ALT+F4. With VB6 this was as simple as setting the form to borderless, but in .NET it will close it reguardless.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

So translate it to VB.NET :p

Private Sub Form1_Closing(sender As object, e As System.ComponentModel.CancelEventArgs) Handles Form1.Closing
    e.Cancel = True ' Cancel closing of form
End Sub

Link to comment
Share on other sites

  • 0

Thanks for the pointers, I'm only just moving to .net from VB6, and it has been confusing at times. I got it to work using the code provided as a base, and I'm pleased with the result :D.

Link to comment
Share on other sites

  • 0

Make sure you handle the process of closing the application when the OS is shutting down, if your app cancels from being closed, when your app is still running and you shutdown your comp, your app halts the shutdown process.

Link to comment
Share on other sites

  • 0
Make sure you handle the process of closing the application when the OS is shutting down, if your app cancels from being closed, when your app is still running and you shutdown your comp, your app halts the shutdown process.

584768485[/snapback]

   Private Const WM_QUERYENDSESSION As System.Int32 = &H11
    Private Const WM_CANCELMODE As System.Int32 = &H1F
    Protected Overrides Sub WndProc(ByRef m As Message)
   	 If m.Msg = WM_QUERYENDSESSION Then
'Put something in here.
   	 Else
      MyBase.WndProc(m)
   	 End If
    End Sub

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.