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

  • SEARCH
  • Home
  • 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 7864031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:40:04+00:00 2026-06-02T23:40:04+00:00

I have a form in VB.NET that is used as a dialog in a

  • 0

I have a form in VB.NET that is used as a dialog in a mainform. Its instances are always locally defined, there’s no field for it. When the user clicks the OK button in the dialog, it will fire an event with exactly one argument, an instance of one of my classes.

Since it is always a local variable, how can I add an event handler for that event? I’ve searched for myself and found something but I can’t really figure it out…

Code for the event, a field in MyDialog:

public Event ObjectCreated(ByRef newMyObject as MyObject)

Code for the main form to call dialog : (never mind the syntax)

Dim dialog As New MyDialog()
dialog.ShowDialog(Me)
AddHandler ObjectCreated, (what do I put here?) //Or how do I add a handler?

As you can see I’m stuck on how to add a handler for my event. Can anyone help me? Preferrably with the best way to do it…

  • 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-06-02T23:40:06+00:00Added an answer on June 2, 2026 at 11:40 pm

    It’s recommended, for consistency, that you use the same source and event args model as all system event handlers.

    Create your own class inheriting from EventArgs, as:

    Public Class MyObjectEventArgs
        Inherits EventArgs
    
        Public Property EventObject As MyObject
    
    End Class
    

    Then declare your event, and a handler method, like:

    Public Event ObjectCreated As EventHandler(Of MyObjectEventArgs)
    
    Private Sub Container_ObjectCreated(ByVal sender As Object, ByVal e As MyObjectEventArgs)
        ' Handler code here
    End Sub
    

    Then attach the handler to your event using:

    AddHandler ObjectCreated, AddressOf Container_ObjectCreated
    

    Additionally, you can use the Handles to attach to the event raised from your main form (assuming the name MainForm), as below:

    Private Sub MainForm_ObjectCreated(ByVal sender As Object, ByVal e As MyObjectEventArgs) Handles MainForm.ObjectCreated
        ' Handler code here
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET form that the user can make lots of changes to,
I have an asp.net form that contains some html, 2 controls a calendar from
I have application in VB.net that have two different form (Form1 and Form2). Now
I have an ASP.NET MVC form that when submitted can return either an ActionResult
I have an ASP.NET form (C#) but which I click this button that should
I have a pretty simple ASP.NET Web Form that looks a bit like the
I have an asp.net web form (c#, .NET framework 3.5) that returns to itself
JI have written a .NET C# Windows Form app in Visual Studio 2008 that
i have an asp.net mvc app that has a form that uploads a file.
I have an ASP.NET page that contains a form and a button. In order

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.