Need help with raising event in New() event in a base form 
Author Message
 Need help with raising event in New() event in a base form

I have two forms, one which is a base form and another which is inherited
from the base form.  In the base form I have the following:

Public Event Initialize()

Public Sub New()

    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call
    RaiseEvent Initialize()

End Sub

I did this to provide a nice Initialize event in the inherited form.  When
the inherited form is being created, I can trace through the code to see the
RaiseEvent Initialize() being called in the base form's constructor, but the
corresponding event does not fire in the inherited form.  Why does it not
fire?

In the same base form I have another event called QueryUnload that gets
raised and it works (it gets raised in a handler for WndProc and simulates
the QueryUnload event from VB6).  I don't know why this one works and the
other one does not.

- Don

P.S.: Here is the entirety of the base form's code:

Public Class frmBaseForm
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        RaiseEvent Initialize()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.De{*filter*}StepThrough()> Private Sub
InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(frmBaseForm))
        '
        'frmBaseForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
        Me.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"),
System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "frmBaseForm"

    End Sub

#End Region

    '
****************************************************************************
****************
    ' *** EVENTS
****************************************************************************
****
    '
****************************************************************************
****************

    ' We'll use this to implement the QueryUnload event that M$ left out of
VB.NET
    ' NOTE: Not all unload modes are handled!  I've just implemented the few
that I found out how to.
    Public Event QueryUnload(ByVal UnloadMode As eUnloadMode, ByVal e As
System.ComponentModel.CancelEventArgs)

    ' This event is fired from the New event.  It makes code easier to read
because you don't have to
    ' go into the Windows Generated Code region to get at the New()
constructor method to put initialization
    ' code in for you form; you can just use this event in the portion of
the code window where you
    ' keep your code together
    Public Event Initialize()

    '
****************************************************************************
****************
    ' *** CONSTANTS
****************************************************************************
**
    '
****************************************************************************
****************

    Protected Const WM_QUERYENDSESSION As Integer = &H11
    'Protected Const WM_ENDSESSION As Integer = &H16
    'Protected Const WM_DESTROY As Integer = &H2
    Protected Const WM_CLOSE As Integer = &H10
    Protected Const WM_SYSCOMMAND As Integer = &H112
    Protected Const SC_CLOSE As Integer = &HF060&

    '
****************************************************************************
****************
    ' *** ENUMERATED TYPES
***********************************************************************
    '
****************************************************************************
****************

    Public Enum eUnloadMode
        ControlMenu = 0
        Code = 1
        SessionClosing = 2
        TaskManager = 3
        MDIParentClosing = 4
        OwnerClosing = 5
    End Enum

    '
****************************************************************************
****************
    ' *** VARIABLES
****************************************************************************
**
    '
****************************************************************************
****************

    '
****************************************************************************
****************
    '
****************************************************************************
****************
    '
****************************************************************************
****************

    Protected Friend Sub CloseForm()
        ' Close the form.
        Me.Close()
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

        ' DD Apr 23/03
        '
        ' This event traps messages received by the form

        Dim oCancelEvent As New System.ComponentModel.CancelEventArgs()

        Select Case m.Msg

            Case WM_QUERYENDSESSION

                ' Raise our QueryUnload event
                RaiseEvent QueryUnload(eUnloadMode.SessionClosing,
oCancelEvent)

                ' If we're not supposed to cancel the closing of the form,
then proces the message normally
                If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

            Case WM_SYSCOMMAND

                ' Check to see if the user clicked on the X button or the
Close item on the toolbar menu
                If (m.WParam.ToInt32 And SC_CLOSE) = SC_CLOSE Then
                    ' Raise our QueryUnload event
                    RaiseEvent QueryUnload(eUnloadMode.ControlMenu,
oCancelEvent)
                    ' If we're not supposed to cancel the closing of the
form, then proces the message normally
                    If Not oCancelEvent.Cancel Then MyBase.WndProc(m)
                Else
                    ' Allow base form to handle mssage normally
                    MyBase.WndProc(m)
                End If

            Case WM_CLOSE

                ' Raise our QueryUnload event
                RaiseEvent QueryUnload(eUnloadMode.Code, oCancelEvent)

                ' If we're not supposed to cancel the closing of the form,
then proces the message normally
                If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

            Case Else

                ' Allow base form to handle mssage normally
                MyBase.WndProc(m)

        End Select

    End Sub

End Class



Sun, 23 Oct 2005 23:19:39 GMT  
 Need help with raising event in New() event in a base form
Don,

I think the problem maybe that the window handle for the form has not been
created yet...  You can foce it to be by accessing Me.Handle.  Try adding a
line like this, just before the raise event...

Dim handle As IntPtr = Me.Handle

Tom Shelton


Quote:

> I have two forms, one which is a base form and another which is inherited
> from the base form.  In the base form I have the following:

> Public Event Initialize()

> Public Sub New()

>     MyBase.New()

>     'This call is required by the Windows Form Designer.
>     InitializeComponent()

>     'Add any initialization after the InitializeComponent() call
>     RaiseEvent Initialize()

> End Sub

> I did this to provide a nice Initialize event in the inherited form.  When
> the inherited form is being created, I can trace through the code to see
the
> RaiseEvent Initialize() being called in the base form's constructor, but
the
> corresponding event does not fire in the inherited form.  Why does it not
> fire?

> In the same base form I have another event called QueryUnload that gets
> raised and it works (it gets raised in a handler for WndProc and simulates
> the QueryUnload event from VB6).  I don't know why this one works and the
> other one does not.

> - Don

> P.S.: Here is the entirety of the base form's code:

> Public Class frmBaseForm
>     Inherits System.Windows.Forms.Form

> #Region " Windows Form Designer generated code "

>     Public Sub New()
>         MyBase.New()

>         'This call is required by the Windows Form Designer.
>         InitializeComponent()

>         'Add any initialization after the InitializeComponent() call
>         RaiseEvent Initialize()

>     End Sub

>     'Form overrides dispose to clean up the component list.
>     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>         If disposing Then
>             If Not (components Is Nothing) Then
>                 components.Dispose()
>             End If
>         End If
>         MyBase.Dispose(disposing)
>     End Sub

>     'Required by the Windows Form Designer
>     Private components As System.ComponentModel.IContainer

>     'NOTE: The following procedure is required by the Windows Form
Designer
>     'It can be modified using the Windows Form Designer.
>     'Do not modify it using the code editor.
>     <System.Diagnostics.De{*filter*}StepThrough()> Private Sub
> InitializeComponent()
>         Dim resources As System.Resources.ResourceManager = New
> System.Resources.ResourceManager(GetType(frmBaseForm))
>         '
>         'frmBaseForm
>         '
>         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
>         Me.ClientSize = New System.Drawing.Size(292, 273)
>         Me.Font = New System.Drawing.Font("Tahoma", 8.25!,
> System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
> CType(0, Byte))
>         Me.FormBorderStyle =
> System.Windows.Forms.FormBorderStyle.FixedSingle
>         Me.Icon = CType(resources.GetObject("$this.Icon"),
> System.Drawing.Icon)
>         Me.MaximizeBox = False
>         Me.Name = "frmBaseForm"

>     End Sub

> #End Region

>     '

****************************************************************************
Quote:
> ****************
>     ' *** EVENTS

****************************************************************************
Quote:
> ****
>     '

****************************************************************************

- Show quoted text -

Quote:
> ****************

>     ' We'll use this to implement the QueryUnload event that M$ left out
of
> VB.NET
>     ' NOTE: Not all unload modes are handled!  I've just implemented the
few
> that I found out how to.
>     Public Event QueryUnload(ByVal UnloadMode As eUnloadMode, ByVal e As
> System.ComponentModel.CancelEventArgs)

>     ' This event is fired from the New event.  It makes code easier to
read
> because you don't have to
>     ' go into the Windows Generated Code region to get at the New()
> constructor method to put initialization
>     ' code in for you form; you can just use this event in the portion of
> the code window where you
>     ' keep your code together
>     Public Event Initialize()

>     '

****************************************************************************
Quote:
> ****************
>     ' *** CONSTANTS

****************************************************************************
Quote:
> **
>     '

****************************************************************************
Quote:
> ****************

>     Protected Const WM_QUERYENDSESSION As Integer = &H11
>     'Protected Const WM_ENDSESSION As Integer = &H16
>     'Protected Const WM_DESTROY As Integer = &H2
>     Protected Const WM_CLOSE As Integer = &H10
>     Protected Const WM_SYSCOMMAND As Integer = &H112
>     Protected Const SC_CLOSE As Integer = &HF060&

>     '

****************************************************************************
Quote:
> ****************
>     ' *** ENUMERATED TYPES
> ***********************************************************************
>     '

****************************************************************************
Quote:
> ****************

>     Public Enum eUnloadMode
>         ControlMenu = 0
>         Code = 1
>         SessionClosing = 2
>         TaskManager = 3
>         MDIParentClosing = 4
>         OwnerClosing = 5
>     End Enum

>     '

****************************************************************************
Quote:
> ****************
>     ' *** VARIABLES

****************************************************************************
Quote:
> **
>     '

****************************************************************************
Quote:
> ****************

>     '

****************************************************************************
Quote:
> ****************
>     '

****************************************************************************
Quote:
> ****************
>     '

****************************************************************************
Quote:
> ****************

>     Protected Friend Sub CloseForm()
>         ' Close the form.
>         Me.Close()
>     End Sub

>     Protected Overrides Sub WndProc(ByRef m As

System.Windows.Forms.Message)

- Show quoted text -

Quote:

>         ' DD Apr 23/03
>         '
>         ' This event traps messages received by the form

>         Dim oCancelEvent As New System.ComponentModel.CancelEventArgs()

>         Select Case m.Msg

>             Case WM_QUERYENDSESSION

>                 ' Raise our QueryUnload event
>                 RaiseEvent QueryUnload(eUnloadMode.SessionClosing,
> oCancelEvent)

>                 ' If we're not supposed to cancel the closing of the form,
> then proces the message normally
>                 If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

>             Case WM_SYSCOMMAND

>                 ' Check to see if the user clicked on the X button or the
> Close item on the toolbar menu
>                 If (m.WParam.ToInt32 And SC_CLOSE) = SC_CLOSE Then
>                     ' Raise our QueryUnload event
>                     RaiseEvent QueryUnload(eUnloadMode.ControlMenu,
> oCancelEvent)
>                     ' If we're not supposed to cancel the closing of the
> form, then proces the message normally
>                     If Not oCancelEvent.Cancel Then MyBase.WndProc(m)
>                 Else
>                     ' Allow base form to handle mssage normally
>                     MyBase.WndProc(m)
>                 End If

>             Case WM_CLOSE

>                 ' Raise our QueryUnload event
>                 RaiseEvent QueryUnload(eUnloadMode.Code, oCancelEvent)

>                 ' If we're not supposed to cancel the closing of the form,
> then proces the message normally
>                 If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

>             Case Else

>                 ' Allow base form to handle mssage normally
>                 MyBase.WndProc(m)

>         End Select

>     End Sub

> End Class



Sun, 23 Oct 2005 23:35:45 GMT  
 Need help with raising event in New() event in a base form

That might work, but I've realized a flaw in my approach.  I wanted this
Initialize event to be used by all derived forms, but if the event is fired
by the base form's New event, then the Initialize event will occur before
the components on the derived form are initialized by the windows generated
code.  Controls on the form become inaccessible, which defeats the purpose
of the Initialize event.

I managed to get it working by declaring the Initialize() sub in the base
form as just "Overridable" (no Friend or Private or anything), then
overriding that sub in the derived class.  Unfortunately, all the controls I
wanted to initialize were set to Nothing because of the aforementioned
problem.

I'll just have to stick with something less complicated then.  No big deal.

- Don


Quote:
> Don,

> I think the problem maybe that the window handle for the form has not been
> created yet...  You can foce it to be by accessing Me.Handle.  Try adding
a
> line like this, just before the raise event...

> Dim handle As IntPtr = Me.Handle

> Tom Shelton



> > I have two forms, one which is a base form and another which is
inherited
> > from the base form.  In the base form I have the following:

> > Public Event Initialize()

> > Public Sub New()

> >     MyBase.New()

> >     'This call is required by the Windows Form Designer.
> >     InitializeComponent()

> >     'Add any initialization after the InitializeComponent() call
> >     RaiseEvent Initialize()

> > End Sub

> > I did this to provide a nice Initialize event in the inherited form.
When
> > the inherited form is being created, I can trace through the code to see
> the
> > RaiseEvent Initialize() being called in the base form's constructor, but
> the
> > corresponding event does not fire in the inherited form.  Why does it
not
> > fire?

> > In the same base form I have another event called QueryUnload that gets
> > raised and it works (it gets raised in a handler for WndProc and
simulates
> > the QueryUnload event from VB6).  I don't know why this one works and
the
> > other one does not.

> > - Don

> > P.S.: Here is the entirety of the base form's code:

> > Public Class frmBaseForm
> >     Inherits System.Windows.Forms.Form

> > #Region " Windows Form Designer generated code "

> >     Public Sub New()
> >         MyBase.New()

> >         'This call is required by the Windows Form Designer.
> >         InitializeComponent()

> >         'Add any initialization after the InitializeComponent() call
> >         RaiseEvent Initialize()

> >     End Sub

> >     'Form overrides dispose to clean up the component list.
> >     Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
> >         If disposing Then
> >             If Not (components Is Nothing) Then
> >                 components.Dispose()
> >             End If
> >         End If
> >         MyBase.Dispose(disposing)
> >     End Sub

> >     'Required by the Windows Form Designer
> >     Private components As System.ComponentModel.IContainer

> >     'NOTE: The following procedure is required by the Windows Form
> Designer
> >     'It can be modified using the Windows Form Designer.
> >     'Do not modify it using the code editor.
> >     <System.Diagnostics.De{*filter*}StepThrough()> Private Sub
> > InitializeComponent()
> >         Dim resources As System.Resources.ResourceManager = New
> > System.Resources.ResourceManager(GetType(frmBaseForm))
> >         '
> >         'frmBaseForm
> >         '
> >         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
> >         Me.ClientSize = New System.Drawing.Size(292, 273)
> >         Me.Font = New System.Drawing.Font("Tahoma", 8.25!,
> > System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
> > CType(0, Byte))
> >         Me.FormBorderStyle =
> > System.Windows.Forms.FormBorderStyle.FixedSingle
> >         Me.Icon = CType(resources.GetObject("$this.Icon"),
> > System.Drawing.Icon)
> >         Me.MaximizeBox = False
> >         Me.Name = "frmBaseForm"

> >     End Sub

> > #End Region

> >     '

****************************************************************************
Quote:
> > ****************
> >     ' *** EVENTS

****************************************************************************
Quote:
> > ****
> >     '

****************************************************************************

- Show quoted text -

Quote:
> > ****************

> >     ' We'll use this to implement the QueryUnload event that M$ left out
> of
> > VB.NET
> >     ' NOTE: Not all unload modes are handled!  I've just implemented the
> few
> > that I found out how to.
> >     Public Event QueryUnload(ByVal UnloadMode As eUnloadMode, ByVal e As
> > System.ComponentModel.CancelEventArgs)

> >     ' This event is fired from the New event.  It makes code easier to
> read
> > because you don't have to
> >     ' go into the Windows Generated Code region to get at the New()
> > constructor method to put initialization
> >     ' code in for you form; you can just use this event in the portion
of
> > the code window where you
> >     ' keep your code together
> >     Public Event Initialize()

> >     '

****************************************************************************
Quote:
> > ****************
> >     ' *** CONSTANTS

****************************************************************************
Quote:
> > **
> >     '

****************************************************************************
Quote:
> > ****************

> >     Protected Const WM_QUERYENDSESSION As Integer = &H11
> >     'Protected Const WM_ENDSESSION As Integer = &H16
> >     'Protected Const WM_DESTROY As Integer = &H2
> >     Protected Const WM_CLOSE As Integer = &H10
> >     Protected Const WM_SYSCOMMAND As Integer = &H112
> >     Protected Const SC_CLOSE As Integer = &HF060&

> >     '

****************************************************************************
Quote:
> > ****************
> >     ' *** ENUMERATED TYPES
> > ***********************************************************************
> >     '

****************************************************************************
Quote:
> > ****************

> >     Public Enum eUnloadMode
> >         ControlMenu = 0
> >         Code = 1
> >         SessionClosing = 2
> >         TaskManager = 3
> >         MDIParentClosing = 4
> >         OwnerClosing = 5
> >     End Enum

> >     '

****************************************************************************
Quote:
> > ****************
> >     ' *** VARIABLES

****************************************************************************
Quote:
> > **
> >     '

****************************************************************************
Quote:
> > ****************

> >     '

****************************************************************************
Quote:
> > ****************
> >     '

****************************************************************************
Quote:
> > ****************
> >     '

****************************************************************************

- Show quoted text -

Quote:
> > ****************

> >     Protected Friend Sub CloseForm()
> >         ' Close the form.
> >         Me.Close()
> >     End Sub

> >     Protected Overrides Sub WndProc(ByRef m As
> System.Windows.Forms.Message)

> >         ' DD Apr 23/03
> >         '
> >         ' This event traps messages received by the form

> >         Dim oCancelEvent As New System.ComponentModel.CancelEventArgs()

> >         Select Case m.Msg

> >             Case WM_QUERYENDSESSION

> >                 ' Raise our QueryUnload event
> >                 RaiseEvent QueryUnload(eUnloadMode.SessionClosing,
> > oCancelEvent)

> >                 ' If we're not supposed to cancel the closing of the
form,
> > then proces the message normally
> >                 If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

> >             Case WM_SYSCOMMAND

> >                 ' Check to see if the user clicked on the X button or
the
> > Close item on the toolbar menu
> >                 If (m.WParam.ToInt32 And SC_CLOSE) = SC_CLOSE Then
> >                     ' Raise our QueryUnload event
> >                     RaiseEvent QueryUnload(eUnloadMode.ControlMenu,
> > oCancelEvent)
> >                     ' If we're not supposed to cancel the closing of the
> > form, then proces the message normally
> >                     If Not oCancelEvent.Cancel Then MyBase.WndProc(m)
> >                 Else
> >                     ' Allow base form to handle mssage normally
> >                     MyBase.WndProc(m)
> >                 End If

> >             Case WM_CLOSE

> >                 ' Raise our QueryUnload event
> >                 RaiseEvent QueryUnload(eUnloadMode.Code, oCancelEvent)

> >                 ' If we're not supposed to cancel the closing of the
form,
> > then proces the message normally
> >                 If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

> >             Case Else

> >                 ' Allow base form to handle mssage normally
> >                 MyBase.WndProc(m)

> >         End Select

> >     End Sub

> > End Class



Sun, 23 Oct 2005 23:41:15 GMT  
 Need help with raising event in New() event in a base form
Hi Don,

The reason for the event not being handled is that the handler isn't added
until after the base form's constructor is called. So, the event is fired,
but there's no handler to catch it. If you're curious, you can see this by
using ildasm to open your exe. By double clicking the constructor of the
derived form, you'll see that add_Initialize (which hooks up the handler to
the event) is called long after the base form's constructor.

Hope this helps,
Craig, VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Quote:
>X-Trace-PostClient-IP: 24.82.192.252

>Newsgroups: microsoft.public.dotnet.languages.vb
>Subject: Need help with raising event in New() event in a base form
>Lines: 256
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2720.3000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

>Date: Wed, 07 May 2003 15:19:39 GMT
>NNTP-Posting-Host: 24.66.94.143

>X-Trace: news1.calgary.shaw.ca 1052320779 24.66.94.143 (Wed, 07 May 2003
09:19:39 MDT)
>NNTP-Posting-Date: Wed, 07 May 2003 09:19:39 MDT
>Organization: Shaw Residential Internet
>Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!newsfeed.icl.net!newsfeed.fjserv.net!c03.atl99!sjc70.webusenet.com!news
webusenet.com!pd2nf1so.cg.shawcable.net!residential.shaw.ca!news1.calgary.s
haw.ca.POSTED!not-for-mail

- Show quoted text -

Quote:
>Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:106333
>X-Tomcat-NG: microsoft.public.dotnet.languages.vb

>I have two forms, one which is a base form and another which is inherited
>from the base form.  In the base form I have the following:

>Public Event Initialize()

>Public Sub New()

>    MyBase.New()

>    'This call is required by the Windows Form Designer.
>    InitializeComponent()

>    'Add any initialization after the InitializeComponent() call
>    RaiseEvent Initialize()

>End Sub

>I did this to provide a nice Initialize event in the inherited form.  When
>the inherited form is being created, I can trace through the code to see
the
>RaiseEvent Initialize() being called in the base form's constructor, but
the
>corresponding event does not fire in the inherited form.  Why does it not
>fire?

>In the same base form I have another event called QueryUnload that gets
>raised and it works (it gets raised in a handler for WndProc and simulates
>the QueryUnload event from VB6).  I don't know why this one works and the
>other one does not.

>- Don

>P.S.: Here is the entirety of the base form's code:

>Public Class frmBaseForm
>    Inherits System.Windows.Forms.Form

>#Region " Windows Form Designer generated code "

>    Public Sub New()
>        MyBase.New()

>        'This call is required by the Windows Form Designer.
>        InitializeComponent()

>        'Add any initialization after the InitializeComponent() call
>        RaiseEvent Initialize()

>    End Sub

>    'Form overrides dispose to clean up the component list.
>    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
>        If disposing Then
>            If Not (components Is Nothing) Then
>                components.Dispose()
>            End If
>        End If
>        MyBase.Dispose(disposing)
>    End Sub

>    'Required by the Windows Form Designer
>    Private components As System.ComponentModel.IContainer

>    'NOTE: The following procedure is required by the Windows Form Designer
>    'It can be modified using the Windows Form Designer.
>    'Do not modify it using the code editor.
>    <System.Diagnostics.De{*filter*}StepThrough()> Private Sub
>InitializeComponent()
>        Dim resources As System.Resources.ResourceManager = New
>System.Resources.ResourceManager(GetType(frmBaseForm))
>        '
>        'frmBaseForm
>        '
>        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
>        Me.ClientSize = New System.Drawing.Size(292, 273)
>        Me.Font = New System.Drawing.Font("Tahoma", 8.25!,
>System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
>CType(0, Byte))
>        Me.FormBorderStyle =
>System.Windows.Forms.FormBorderStyle.FixedSingle
>        Me.Icon = CType(resources.GetObject("$this.Icon"),
>System.Drawing.Icon)
>        Me.MaximizeBox = False
>        Me.Name = "frmBaseForm"

>    End Sub

>#End Region

>    '
>***************************************************************************
*
>****************
>    ' *** EVENTS
>***************************************************************************
*
>****
>    '
>***************************************************************************
*
>****************

>    ' We'll use this to implement the QueryUnload event that M$ left out of
>VB.NET
>    ' NOTE: Not all unload modes are handled!  I've just implemented the
few
>that I found out how to.
>    Public Event QueryUnload(ByVal UnloadMode As eUnloadMode, ByVal e As
>System.ComponentModel.CancelEventArgs)

>    ' This event is fired from the New event.  It makes code easier to read
>because you don't have to
>    ' go into the Windows Generated Code region to get at the New()
>constructor method to put initialization
>    ' code in for you form; you can just use this event in the portion of
>the code window where you
>    ' keep your code together
>    Public Event Initialize()

>    '
>***************************************************************************
*
>****************
>    ' *** CONSTANTS
>***************************************************************************
*
>**
>    '
>***************************************************************************
*
>****************

>    Protected Const WM_QUERYENDSESSION As Integer = &H11
>    'Protected Const WM_ENDSESSION As Integer = &H16
>    'Protected Const WM_DESTROY As Integer = &H2
>    Protected Const WM_CLOSE As Integer = &H10
>    Protected Const WM_SYSCOMMAND As Integer = &H112
>    Protected Const SC_CLOSE As Integer = &HF060&

>    '
>***************************************************************************
*
>****************
>    ' *** ENUMERATED TYPES
>***********************************************************************
>    '
>***************************************************************************
*
>****************

>    Public Enum eUnloadMode
>        ControlMenu = 0
>        Code = 1
>        SessionClosing = 2
>        TaskManager = 3
>        MDIParentClosing = 4
>        OwnerClosing = 5
>    End Enum

>    '
>***************************************************************************
*
>****************
>    ' *** VARIABLES
>***************************************************************************
*
>**
>    '
>***************************************************************************
*
>****************

>    '
>***************************************************************************
*
>****************
>    '
>***************************************************************************
*
>****************
>    '
>***************************************************************************
*
>****************

>    Protected Friend Sub CloseForm()
>        ' Close the form.
>        Me.Close()
>    End Sub

>    Protected Overrides Sub WndProc(ByRef m As

System.Windows.Forms.Message)

- Show quoted text -

Quote:

>        ' DD Apr 23/03
>        '
>        ' This event traps messages received by the form

>        Dim oCancelEvent As New System.ComponentModel.CancelEventArgs()

>        Select Case m.Msg

>            Case WM_QUERYENDSESSION

>                ' Raise our QueryUnload event
>                RaiseEvent QueryUnload(eUnloadMode.SessionClosing,
>oCancelEvent)

>                ' If we're not supposed to cancel the closing of the form,
>then proces the message normally
>                If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

>            Case WM_SYSCOMMAND

>                ' Check to see if the user clicked on the X button or the
>Close item on the toolbar menu
>                If (m.WParam.ToInt32 And SC_CLOSE) = SC_CLOSE Then
>                    ' Raise our QueryUnload event
>                    RaiseEvent QueryUnload(eUnloadMode.ControlMenu,
>oCancelEvent)
>                    ' If we're not supposed to cancel the closing of the
>form, then proces the message normally
>                    If Not oCancelEvent.Cancel Then MyBase.WndProc(m)
>                Else
>                    ' Allow base form to handle mssage normally
>                    MyBase.WndProc(m)
>                End If

>            Case WM_CLOSE

>                ' Raise our QueryUnload event
>                RaiseEvent QueryUnload(eUnloadMode.Code, oCancelEvent)

>                ' If we're not supposed to cancel the closing of the form,
>then proces the message normally
>                If Not oCancelEvent.Cancel Then MyBase.WndProc(m)

>            Case Else

>                ' Allow base form to handle mssage normally
>                MyBase.WndProc(m)

>        End Select

>    End Sub

>End Class



Mon, 24 Oct 2005 08:56:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how to raise base class event and method from the derived child object

2. Raise base class events or override them

3. Help needed raising events from ActiveX DLL

4. Help needed raising events from ActiveX DLL

5. Raise event does not trigger event at the client

6. raising an event log event from the workstation

7. Need Guidance For Raise Events

8. raise an event from a form of an ActiveX dll

9. OLE server with a form, raising an event....

10. OLE server with a form, raising an event....

11. raising event from form in ActiveX dll

12. new VB. user need help with Change Event

 

 
Powered by phpBB® Forum Software