Solved

How do I program the x button?

Posted on 2007-03-27
2
159 Views
Last Modified: 2010-04-23
How do I program the x button in the top right to do whatever I want?
0
Comment
Question by:Kael1
2 Comments
 
LVL 7

Expert Comment

by:JuanCarniglia
ID: 18799579
You don't do that exactly, but you can do this.

Capture the Event (Unload) on that form, and choose to close it or not, or to do something else.
Try this:

------

Private Sub Form_Unload(Cancel As Integer)

    MsgBox ("This will appear when I click the x button !!! ")

    if (I_Want_To_Close_This_Window) Then
           
           'Close all files and handles

           Cancel = 0      'This means that this event will get passed on
    Else
           'Do something else

           Cancel = 1     'This means that this event will NOT get passed on
    End If

End Sub

-------

Greetings
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 18800597
For VB.Net, it's similar...

In VB.Net 2005:

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Select Case e.CloseReason
            Case CloseReason.UserClosing
                If somecondition Then
                    e.Cancel = True
                End If

        End Select
    End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question