Solved

Why isn't WM_CLOSE firing for a component in VB.NET

Posted on 2006-11-29
6
339 Views
Last Modified: 2008-02-01
I have derived a custom component from TextBox.
When the parent form is closing, I want to respond by closing a form that was opened.
But the code inside the following If statement doesn't get called.

What is necessary so that component gets the WM_CLOSE message?

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_CLOSE As Integer = &H10

        If m.Msg = WM_CLOSE Then
            BBHelpBubble.Instance.Close()
        End If

        MyBase.WndProc(m)
    End Sub
0
Comment
Question by:brotherbill999
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18041318
Hi brotherbill999,

I may be missing something here, but why not use:

Private Sub Form_closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
  BBHelpBubble.Instance.Close()
End Sub

Cheers,
Hillwaaa
0
 

Author Comment

by:brotherbill999
ID: 18041373
This is a component, so there doesn't seem to be a Form_Closing event to attach to.

Public Class BBTextBox
    Inherits TextBox
    ' ...
End Class
0
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 18041451
Sorry - I meant to put that in the parent form, not in the custom component.  That way when the parent form is closing you can automatically close the form that was opened (although you may want to check that it is actually open).

Am I misunderstanding your quesiton?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:brotherbill999
ID: 18041643
Yes, as a component author, I don't have control over the form that it goes into,
and the component should not require the consuming user to do anything other
than slap it on the form, set properties, and handle events.

They should not need to do housekeeping for the component's internals.
So, what I'm asking is how to respond to the event where the component's form
is closing.

Brother Bill
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 500 total points
ID: 18041776
Ah, ok now I see...

I've not done much in this before - perhaps you could use the dispose method instead?

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If Not (<<test For BBHelpBubble>>) Then
                BBHelpBubble.Instance.Close()
            End If
        MyBase.Dispose(disposing)
    End Sub
0
 

Author Comment

by:brotherbill999
ID: 18042502
Already has the Dispose code, but it wasn't firing.
The trick is that in the following code, it is critical to manually close the form.
Don't know why, as clicking the red Close Box already closed the form, but without firing Dispose!

           Dim frm As New frmMcM_trucking_driver()
           Dim rc As DialogResult = frm.ShowDialog()
           ' do something
   
           'Add this line, which caused frm.Dispose() to fire.   ' <<<<<<<
           frm.Close()                                                         ' <<<<<<<
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.

Question has a verified solution.

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

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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