Solved

What event fires when...

Posted on 2012-03-15
2
231 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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