0

I want to after clicking on button2,after that if i click on button1 then msg is not displayed

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("sonia")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RemoveHandler Button2.Click, AddressOf MYEVENTHandler
    End Sub

    Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
3
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by hscoder
0

I want to after clicking on button2,after that if i click on button1 then msg is not displayed

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox("sonia")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        RemoveHandler Button2.Click, AddressOf MYEVENTHandler
    End Sub

    Private Sub MYEVENTHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class

In your Form Load, setup the event handler for Button1. So, remove the statement Handles Button1.Click at the end of the Button1.Click procedure.

In your Form_Load place the following:
Addhandler Button1.Click, AddressOf MYEVENTHandler

In your MYEVENTHandler place the following code:
msgbox ("sonia")

In the Button2_Click, use the existing code you have, it will work.

Hope this helps.

Edited by CodeDoctor: typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.