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 342133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:46:28+00:00 2026-05-12T10:46:28+00:00

IN VB.NET (not c#)… I want to create an event than can be canceled

  • 0

IN VB.NET (not c#)…

I want to create an event than can be canceled by the listener. Just like you can cancel the closing event of a winforms form in which case the form won’t close.

I have already implemented a derived class from EventArgs that has a settable Cancel property as follows:

Public Class AnnounceNavigateEventArgs
    Inherits EventArgs

    Private _cancel As Boolean = False

    ''' <summary>
    ''' Initializes a new instance of the AnnounceNavigateEventArgs class.
    ''' </summary>
    Public Sub New(ByRef cancel As Boolean)
        _cancel = cancel
    End Sub
    Public Property Cancel() As Boolean
        Get
            Return _cancel
        End Get
        Set(ByVal value As Boolean)
            _cancel = value
        End Set
    End Property

End Class

Notice that I am passing the cancel argument byRef to the constructor.

The listener I have setup is setting the property to Cancel=True. I thought ByRef meant that both _cancel and cancel would point to the same location on the stack and that setting _cancel=true would therefore make the cancel = true. But this is not the behavior I am getting. _cancel becomes true in the setter but I guess the argument to the constructor remains false.

What is the proper way to do this in vb.net?

Seth

  • 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-12T10:46:29+00:00Added an answer on May 12, 2026 at 10:46 am

    You can re-use the System.ComponentModel.CancelEventArgs class in the .NET framework.

    Public Event Announcing As EventHandler(Of AnnounceNavigateEventArgs)
    
    Protected Sub OnAnnounce()
        Dim e As New AnnounceNavigateEventArgs
    
        RaiseEvent Announcing(Me, e)
    
        If Not e.Cancel Then
            ' announce
        End If
    End Sub
    
    Public Class AnnounceNavigateEventArgs
        Inherits System.ComponentModel.CancelEventArgs
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make an installing application using vb.net(not asp.net) where i can login
How can I assign classes to the online/ASP.NET (not a desktop app) version of
Does asp.net (not mvc) support HTML 5? I need to create HTML 5 application,
I know VB.Net does not allow implicit interface implementation like C#. And thus code
I am attempting to write a 'User Control' in WinForms .NET (not ASP.NET). The
I'm interested in learning about parallel programming in C#.NET (not like everything there is
In ASP.NET (not MVC), what is the best approach to programmatically setting styles on
I'm trying to use TestDriven.Net not only to test my code, but to call
There's another post on SO relating to .NET -- not us. Pure PHP. Trying
At what point is it better to switch from java.net to java.nio? .net (not

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.