Solved

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

Posted on 2006-11-29
6
343 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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