Results 1 to 5 of 5

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

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    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 2002
    Posts
    34,687

    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 don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    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

    Thread Starter
    Addicted Member
    Join Date
    Aug 2011
    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 2002
    Posts
    34,687

    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 don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

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