Solved

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

Posted on 2006-11-29
6
337 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
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.

 

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

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

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 I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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