Windows Develop Bookmark and Share   
 index > Windows Forms General > Bold Specific Words
 

Bold Specific Words

Is it possible to bold specific words in say a Rich Textbox on a form.

e.g. The cat sat on the mat.

The phrase would be coded as a variable or constant and entered as the Rich Textbox text at runtime.

This is simple with HTML. I wondered if there was an equivalent feature in VB.Net

Thanks,

DanDare  Friday, February 22, 2008 12:29 AM

This might give you a start:

Code Snippet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim boldFont As Font = New Font(RichTextBox1.Font, FontStyle.Bold)

Dim pos As Integer = 0

While pos < RichTextBox1.TextLength AndAlso _

RichTextBox1.Find("cat", pos, RichTextBoxFinds.WholeWord) <> -1

RichTextBox1.SelectionFont = boldFont

pos += RichTextBox1.SelectionLength

End While

End Sub

BinaryCoder  Saturday, February 23, 2008 4:21 AM

This might give you a start:

Code Snippet

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim boldFont As Font = New Font(RichTextBox1.Font, FontStyle.Bold)

Dim pos As Integer = 0

While pos < RichTextBox1.TextLength AndAlso _

RichTextBox1.Find("cat", pos, RichTextBoxFinds.WholeWord) <> -1

RichTextBox1.SelectionFont = boldFont

pos += RichTextBox1.SelectionLength

End While

End Sub

BinaryCoder  Saturday, February 23, 2008 4:21 AM

Thanks BinaryCoder. That was very helpful. With a bit of modification to suit my requirements I got everything to work fine. Your code pointed me in the right direction.

Thanks again.

DanDare  Saturday, February 23, 2008 11:19 PM

You can use google to search for other answers

Custom Search

More Threads

• Get parent window vb.net
• Double click on a row in datagrid, winapp .net
• using streamwrite into a excel xls. file
• error during some WindowsForms component creation
• Reversed RTL text inside dropdownlist controls!
• Combo box in DataGrid in WinForms VB.net 2003
• Hardware source on Click Event
• RichTextBox Syntax Highlighting issue
• Custom Text Box
• Using More than One language