Results 1 to 3 of 3

Thread: [RESOLVED] Add event hangler

  1. #1

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    814

    Resolved [RESOLVED] Add event hangler

    Hi in VB.NET Express I am trying to make a notes program what it does is aload rtf files from a folder and adds tabs and a ritchtext box. This the code I am using

    Code:
        Private Sub NewNote(ByVal Text As String, Optional ByVal PageData As String = "")
            Dim tp As New TabPage
            Dim rt As New RichTextBox
    
            'Set tabpage caption
            tp.Text = Text
    
            rt.Dock = DockStyle.Fill
            rt.BorderStyle = BorderStyle.None
            rt.Parent = tp
    
            'Check if we have a filename to load.
            If Not String.IsNullOrEmpty(PageData) Then
                rt.LoadFile(PageData)
            End If
    
            'Add new tabpage
            sTab1.TabPages.Add(tp)
        End Sub
    My problum is how can I add an event for TextChanged of the richedit bxoes. I know in C# you can use something like this

    Code:
    rt.TextChanged += new System.EventHandler(TextChange);
    but I duno how you do it in VB can someone please help I used to use VB6 years back then moved to C# and now moved to VB.NET so eveything is sort of new to me.

  2. #2
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Add event hangler

    AddHandler rt.TextChanged, AddressOf TextChange

    Another way (probably more common) in VB is to use a 'Handles' clause on the method header for the event procedure - if you add the event via the designer it will set it up this way. You just have to ensure that the textbox is declared using 'WithEvents' (but it should be if you added it via the designer).
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  3. #3

    Thread Starter
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    814

    Re: Add event hangler

    Thanks David AddHandler works fine. thanks agian.

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