Results 1 to 5 of 5

Thread: How do I add a handler to a dynamically created textbox?

  1. #1
    Addicted Member
    Join Date
    Aug 11
    Posts
    200

    How do I add a handler to a dynamically created textbox?

    In my application, when user adds a new file it adds a new textbox into a new tab. Which that works great. Before I decided to add the multidocument capabilities, I had a contextmenu that became active when the user right clicked the textbox. I still have the code for that which I can re-use I just want to know how I can do the same for my dynamically created textboxes. How do I set it up so I can create a event handler for the dynamic textbox like I would one on design time.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: How do I add a handler to a dynamically created textbox?

    Use AddHandler.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  3. #3
    Addicted Member
    Join Date
    Aug 11
    Posts
    200

    Re: How do I add a handler to a dynamically created textbox?

    Hi tg I should of been more clear.

    I added these to the code I use to add the tabs and textbox
    vb Code:
    1. AddHandler tb.DragDrop, AddressOf tb_DragDrop
    2.         AddHandler tb.MouseUp, AddressOf tb_mouseup
    tb is the textbox I declared.

    I then added my sub for that.

    vb Code:
    1. Private Sub tb_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
    2.         'this appends the listviewitem's tag to the rtb on dragdrop
    3.         Dim page As RadPageViewPage = RadPageView1.SelectedPage
    4.         For Each txt As FastColoredTextBox In page.Controls.OfType(Of FastColoredTextBox)()
    5.             If e.Data.GetDataPresent(GetType(ListViewItem)) Then
    6.                 Dim item As ListViewItem = DirectCast(e.Data.GetData(GetType(ListViewItem)), ListViewItem)
    7.                 txt.AppendText(item.Tag.ToString & Environment.NewLine)
    8.                
    9.                 End If
    10.         Next
    11.     End Sub

    Is this the correct way of doing it? I cannot add the handles tb.dragdrop beside it the sub, Unless I don't need it?

    I have another sub that I need to add the tb. handler to although when I try to add it it says it cannot resolve symbol. I point it out in the code below.


    vb Code:
    1. Private Sub all_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragOver, mainsidemenu.DragOver, ScriptEditor.DragOver <-----I need to add the tb.dragover
    2.         If e.Data.GetDataPresent(GetType(ListViewItem)) Then
    3.             e.Effect = DragDropEffects.All
    4.         End If
    5.     End Sub

    Thanks TG.

  4. #4
    Addicted Member
    Join Date
    Aug 11
    Posts
    200

    Re: How do I add a handler to a dynamically created textbox?

    Looks like I did have it right I just left something out of my other code. Thanks.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,794

    Re: How do I add a handler to a dynamically created textbox?

    Sorry I was on a mobile when I did that reply other wise it would have been more indepth. But yes, the AddHandler is instead of the Handles clause... it allows you to hook and unhook (using RemoveHandler) events to subs... or even rewire handlers... As long as the signature of the sub matches the signature of the event you can hook anything up at run time.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

Posting Permissions

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