How to: Make A Highlighter

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post Page 1 of 1
Contributors
User avatar
3aaBrSbeel
Top Poster
Top Poster
Posts: 139
Joined: Fri Jun 01, 2012 9:34 am

How to: Make A Highlighter
3aaBrSbeel
Hello, guys. This is 3aaBrSbeel. I haven't posted for such a long time so I'm posting a new one lmao;

Okay, this tutorial will show you how to make a highlighter.

You'll need.
  • A RichTextBox
    A Button
    and A TextBox
We'll place the TextBox and the Button up top.
Re-name the buttons text to "Find"
Place the RichTextBox below TextBox and Button.
capture-20130121-212431.png
If you are done with that, double-click the form then you'll have Form_Load.
Add this on Form_Load.
Code: Select all
Try
            If My.Computer.Clipboard.ContainsText() Then
                Dim ClipText As String
                ClipText = My.Computer.Clipboard.GetText
                RichTextBox1.Text = (ClipText)
            End If
        Catch ex As Exception
            MsgBox("Looks like you don't have any last copied text.", MsgBoxStyle.Information, "NiCz Productions")
        End Try
Edit the MsgBox to your desire.
Thanks, #mshimranpro for his "Last Copied Text" tutorial cooll;

Let's continue, add the codes below under Public Class Form
Code: Select all
Dim start As Integer = 0
    Dim indexOfSearchText As Integer = 0
Double-click the Button, copy and paste the codes to Button.
Code: Select all
Dim startindex As Integer = 0

        If TextBox1.Text.Length > 0 Then
            startindex = FindMyText(TextBox1.Text.Trim(), start, RichTextBox1.Text.Length)
        End If

        ' If string was found in the RichTextBox, highlight it
        If startindex >= 0 Then
            ' Set the highlight color as red
            RichTextBox1.SelectionColor = Color.Red
            ' Find the end index. End Index = number of characters in textbox
            Dim endindex As Integer = TextBox1.Text.Length
            ' Highlight the search string
            RichTextBox1.Select(startindex, endindex)
            ' mark the start position after the position of 
            ' last search string
            start = startindex + endindex
        End If


        'RichTextBox1.SelectionColor = Color.Green
        'RichTextBox1.Sele = "World, Hello, I'm NiCz (3aaBrSbeel)"
Double-click TextBox, copy and paste the codes to TextBox.
Code: Select all
start = 0
        indexOfSearchText = 0
Last thing, to make the program functional we need the function.
Copy the codes below and right-click your Form and choose View Source.
Paste the codes between End Sub and End Class.
Code: Select all
Public Function FindMyText(ByVal txtToSearch As String, ByVal searchStart As Integer, ByVal searchEnd As Integer) As Integer
        ' Unselect the previously searched string
        If searchStart > 0 AndAlso searchEnd > 0 AndAlso indexOfSearchText >= 0 Then
            RichTextBox1.Undo()
        End If
        ' Set the return value to -1 by default.
        Dim retVal As Integer = -1
        ' A valid starting index should be specified.
        ' if indexOfSearchText = -1, the end of search
        If searchStart >= 0 AndAlso indexOfSearchText >= 0 Then
            ' A valid ending index 
            If searchEnd > searchStart OrElse searchEnd = -1 Then
                ' Find the position of search string in RichTextBox
                indexOfSearchText = RichTextBox1.Find(txtToSearch, searchStart, searchEnd, RichTextBoxFinds.None)
                ' Determine whether the text was found in richTextBox1.
                If indexOfSearchText <> -1 Then
                    ' Return the index to the specified search text.
                    retVal = indexOfSearchText
                End If
            End If
        End If
        Return retVal
    End Function
That's all, you can highlight the last thing you copied. Thanks for your time on this tutorial thank you. loove;
You do not have the required permissions to view the files attached to this post.
Code'n'Stuff Signature Of 3aaBrSbeel
®║▌│█│║▌║││█║▌║▌║▌
✔ Verified Official Code'n'Stuff account ᵀᴴᴱ ᴼᴿᴵᴳᴵᴻᴬᴸ
Image
1 post Page 1 of 1
Return to “Tutorials”