.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Add and Remove Action

Posted By:santhiyagu       Posted Date: August 28, 2010    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

This code will add and remove the handler using VB.Net
 

vb.net using Handler
Imports System
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Globalization
Imports System.Text
Imports System.Collections

Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New Form1()
        Application.Run(myform)
    End Sub
End Class


Public Class Form1
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked Then
            AddHandler Button1.Click, AddressOf ButtonHandler1
        Else
            RemoveHandler Button1.Click, AddressOf ButtonHandler1
        End If
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton2.Checked Then
            AddHandler Button1.Click, AddressOf ButtonHandler2
        Else
            RemoveHandler Button1.Click, AddressOf ButtonHandler2
        End If
    End Sub

    Private Sub ButtonHandler1(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MessageBox.Show("Button Handler1")
    End Sub
    Private Sub ButtonHandler2(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MessageBox.Show("Button Handler2")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RadioButton1.Checked = True
    End Sub

End Class

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend