• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1280
  • Last Modified:

Remove Control Box X

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.
0
bmiller250
Asked:
bmiller250
  • 2
1 Solution
 
xersoftCommented:
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

0
 
xersoftCommented:
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

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now