Results 1 to 2 of 2

Thread: Button Second Click

  1. #1
    shers is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Aug 2007
    Posts
    80
    Reputation
    74

    Button Second Click

    Hi,

    I have a User Control that contains a Button. This button works for the first click. But the Click Event is not fired in the second click. Please help.

    Here's my code:

    Code:
    Public Sub New()
            MyBase.New()
            ' This call is required by the Windows Form Designer.
            InitializeComponent()
    
            ' Add any initialization after the InitializeComponent() call.
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            AddHandler doc.CommandEnded, AddressOf Me.plineCommandEnded
        End Sub
    
    Private Sub ucTools_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            RemoveHandler doc.CommandEnded, AddressOf Me.plineCommandEnded
        End Sub
    
    Private Sub btnSpace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSpace.Click
            InitializeComponent()
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            CmdStarted = True
            doc.SendStringToExecute("_PLINE" & vbCr, True, False, True)
    End Sub
    Thanks

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,209
    Reputation
    2369
    InitializeComponent sets up the user control by the designer generated code, normally that is only done from the constructor. When you call method that from the button click it creates a new button that is assigned to the WithEvents btnSpace variable, and the new control object is added behind the previous button which is still present in user control. So when you click the button a second time you are clicking the old button that is no longer assigned the withevents variable, and there is no longer event handling for it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking