Solved

What event fires when...

Posted on 2012-03-15
2
232 Views
Last Modified: 2012-03-15
What event fires when mouse moves over X to close the form.

I guess X is part of the form because I tried using on MouseLeave but it didn't work.

Background:

I have few text boxes on a form to accept user input. I also have a button "Default Values" to populate these text boxes if the user chooses to use it.

Because the text boxes have Validated events and doesn't allow blank entries, I have:

    Private Sub butDefaultValues_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles butDefaultValues.MouseEnter

        'to pacify _Validated to use "Default Values" button
        bolUsingDefault = True

    End Sub

 Private Sub butDefaultValues_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles butDefaultValues.MouseLeave

        'to keep _Validated active on leaving butDefaultValues
        bolUsingDefault = False

    End Sub

This means, as soon as the mouse enters "Default Values" button, the flag bolUsingDefault is set True thus using:

Private Sub txtVinNumber_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtVinNumber.Validated

        If bolUsingDefault = True Then Exit Sub
.
.

is bypassed.

Question is how I can implement a similar technique when the user moves the mouse to close the form without _Validated event firing.

Thank you.
0
Comment
Question by:Mike Eghtebas
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37727941
You can do:
Public Class Form1
 
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const SC_CLOSE As Integer = &HF060&
        Const WM_SYSCOMMAND As Integer = &H112
 
        Select Case m.Msg
            Case WM_SYSCOMMAND
                Select Case m.WParam.ToInt32
                    Case SC_CLOSE
                        bolUsingDefault = True
 
                End Select
 
        End Select
 
        MyBase.WndProc(m)
    End Sub

End Class

Open in new window

0
 
LVL 33

Author Closing Comment

by:Mike Eghtebas
ID: 37728107
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

21 Experts available now in Live!

Get 1:1 Help Now