Solved

How do I program the x button?

Posted on 2007-03-27
2
156 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now