Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 206353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:38:18+00:00 2026-05-11T17:38:18+00:00

Ok, so I have a base class which declares the event StatusTextChanged . My

  • 0

Ok, so I have a base class which declares the event StatusTextChanged. My child class, of course cannot directly raise this event.

So I wind up with something like this (for simplicity sake):

Public MustInherit Class FooBase
    Public Event StatusTextChanged(ByVal StatusText As String)
    Protected Sub RaiseStatusTextChangedEvent(ByVal StatusText As String)
        RaiseEvent StatusTextChanged(StatusText)
    End Sub
End Class

And then in the child class I call
MyBase.RaiseStatusTextChangedEvent("something").
Is there a better or more recommended way to do this?

edit: VB.NET or C#, either way it works essentially the same.

edit: So after the responses, I’m at this in the base class, then just set the StatusText property in the child class …

    Public Event StatusTextChanged(ByVal StatusText As String)
    Private _StatusText As String = "Idle."
    Public Property StatusText() As String
        Get
            Return _StatusText
        End Get
        Protected Set(ByVal value As String)
            RaiseEvent StatusTextChanged(value)
        End Set
    End Property
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:38:18+00:00Added an answer on May 11, 2026 at 5:38 pm

    I would say that you are rather close to the recommeneded way (or at least the one I would recommend).

    I would make a few alterations to your code, given a choice:

    • Make StatusTextChanged Protected Overridable
    • Wrap StatusText in a custom EventArgs class
    • Change the StatusTextChanged declaration into Public Event StatusTextChanged As EventHandler(Of YourCustomEventArgs)

    The resulting code:

    The custom eventargs class:

    Public Class TextEventArgs
        Inherits EventArgs
    
        Private _text As String
    
        Public Sub New(ByVal text As String)
            _text = text
        End Sub
    
        Public ReadOnly Property Text() As String
            Get
                Return _text
            End Get
        End Property
    
    End Class
    

    The event implementation in your base class:

    Public Event StatusTextChanged As EventHandler(Of TextEventArgs)
    Protected Overridable Sub OnStatusTextChanged(ByVal e As TextEventArgs)
        RaiseEvent StatusTextChanged(Me, e)
    End Sub
    

    …and finally a code line for raising the event; either in the base class or a class that inherits it:

    OnStatusTextChanged(New TextEventArgs("some text"))
    

    This will be more in line with how events are designed within the rest of the .NET framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class which looks something like this: class Base { public:
I have a base class Node which contains a list of child nodes. Node
This is a rather simple question, I have a base class which implements common
I have a base class which is non-generic with a derived generic class. The
I have an abstract base class which acts as an interface. I have two
I have a base class in which I want to specify the methods a
I have a base class object array into which I have typecasted many different
I have a base class with a property which (the get method) I want
I have a base class Foo that has an Update() function, which I want
I have an abstract base class called Shape from which both Circle and Rectangle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.