0

Hi Guys.

I got two combo boxes, one has numbers from 1-75 and the other one has all system fonts. I have a richtextbox as well. I basically want the user to be able to choose the font and font size from the combo box and then apply to the richtextbox. However I want about two functions. If the user has highlighted selected text then changes should only be applied to the highlighted text, if the user has not highlighted an item but changes fonts or font size, then the changes should be made to the next characters inputed.

How can I do this?

3
Contributors
7
Replies
10
Views
4 Years
Discussion Span
Last Post by Jx_Man
Featured Replies
  • 1

    [QUOTE=CriticalError;1781617]Line 341 is causing the error: that this code [code]Document.SelectionFont = New System.Drawing.Font(fontSelection.Text, Document.SelectionFont.Size, Document.SelectionFont.Style)[/code][/QUOTE] In your first post, you have two comboboxes for Font name and font size. You said that you want to select a font size from combo box and apply it to richtextbox. But i didn't … Read More

0

Try this :

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    RichTextBox1.SelectionFont = New Font("Tahoma", CInt(ComboBox1.SelectedItem.ToString), RichTextBox1.SelectionFont.Style)
End Sub
0

Hi Jx

I got this code

Dim ComboFonts As System.Drawing.Font


        ComboFonts = Document.SelectionFont
        Document.SelectionFont = New System.Drawing.Font(fontSelection.Text, Document.SelectionFont.Size, Document.SelectionFont.Style)

it works but sometimes I get the error below:

Object reference not set to an instance of an object.

I don't exactly know how it happens just randomly.

0

Place the code in a try catch block

Try
'Your code here
Catch ex As Exception
   MsgBox(ex.stacktrace.Tostring)
End Try

This will show the exact line that is throwing the error.

Or, alternately. Test each value before performing the action.

If fontSelection.Text <> "" AND Document.SelectionFont.Size ISNOT Nothing AND Document.SelectionFont.Style ISNOT Nothing Then
End If

Edited by Begginnerdev: n/a

0

Line 341 is causing the error:

that this code

Document.SelectionFont = New System.Drawing.Font(fontSelection.Text, Document.SelectionFont.Size, Document.SelectionFont.Style)
1

Line 341 is causing the error:

that this code

Document.SelectionFont = New System.Drawing.Font(fontSelection.Text, Document.SelectionFont.Size, Document.SelectionFont.Style)

In your first post, you have two comboboxes for Font name and font size.
You said that you want to select a font size from combo box and apply it to richtextbox. But i didn't see it in your code. Did you tried my code?

Document.SelectionFont = New Font(ComboBox2.SelectedItem.ToString, CInt(ComboBox1.SelectedItem.ToString), Document.SelectionFont.Style)

Edited by Jx_Man: n/a

0

That works! Thanks, but your other code never worked. ( the first post)

Edited by CriticalError: n/a

0

That works! Thanks, but your other code never worked. ( the first post)

You're Welcome. :D
Don't forget Mark this thread as Solved.

Edited by Jx_Man: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.