?
Solved

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

Posted on 2006-11-29
6
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 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