Results 1 to 5 of 5

Thread: Doubclick Text Box not working

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Doubclick Text Box not working

    I have created the text box at run time and but when I create a sub routine for a DoubClick, this Sub never run even if I double click the text box to clear the value in it. Below is my code, please help you have any idea why.

    Private WithEvents txtRank As System.Windows.Forms.TextBox

    Private Sub txtBoxCreate()

    Dim txtRank As New TextBox()

    nlApplicant.SuspendLayout()
    With txtRank
    .Width = 20
    .Height = h
    .Location = New Point(x, y)
    .AutoSize = True
    .MaxLength = 2
    .BackColor = System.Drawing.Color.White
    .Visible = True
    .Anchor = AnchorStyles.Bottom
    .Show()
    End With
    pnlApplicant.Controls.Add(txtRank)
    pnlApplicant.ResumeLayout(True)
    End Sub

    Private Sub txtRank_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRank.DoubleClick
    txtRank.Text = ""
    End Sub
    Thanks!

    Chong

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Doubleclick on a textbox worked fine for me. Do you also have something handling the Click event? If so then the SingleClick or Click event will prevent the DoubleClick from happening.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually taking a second peek at your code, you don't ever assign the txtRank that is local to the txtBoxCreate method to the form level txtRank that is set to handle events. In fact I'm not sure it you can assign one to the other like that, but if you can it would be like this in the txtBoxCreate method:

    VB Code:
    1. Me.txtRank=txtRank

    The better way would be to use the AddHandler method to add the event handling:

    VB Code:
    1. AddHandler(txtRank.Click,AddressOf txtRank_DoubleClick)

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I posted an example in this thread (maybe it gives your an idea how handlers work ) . Your code seems a bit weird to me . Why did you declare txtRank inside the sub ?
    http://www.vbforums.com/showthread.p...ighlight=Timer

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Thumbs up

    Thank you very much! I'm greatly appreciated! I'm pretty it has to do with the Addhandler. I'll give that a try.

    Chong

Posting Permissions

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



Click Here to Expand Forum to Full Width