We help IT Professionals succeed at work.

Remove Control Box X

bmiller250
bmiller250 asked
on
Visual Studio .NET 2005   VB.Net 2005  dotNet 2.0

A C# programmer using VB.Net.

We need to remove or disable the X control box on a VB.Net form; you know the one that disposes the form.  We want to keep the minimize and restore down box.
Comment
Watch Question

Commented:
Does this work for you?


    Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
        e.Cancel = True
        MyBase.OnClosing(e)
    End Sub

Open in new window

Commented:
Another example with a message asking if the user is sure they want to close.
Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
        Dim Response As DialogResult
        Response = MessageBox.Show("Are you sure you want to close?", "Close?", MessageBoxButtons.YesNo)
        If Response <> Windows.Forms.DialogResult.Yes Then
            e.Cancel = True
        End If
 
        MyBase.OnClosing(e)
    End Sub

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.