Solved

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

Posted on 2006-11-29
6
336 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

10 Experts available now in Live!

Get 1:1 Help Now