[2005] RichTextBox / Error
I have a richtextbox on my form and when I have text like this:
Welcome
Test normal
Test bold
- Test Bold - Test Bullet
- Test Normal - Test Bullet
Header
http://www.rattlesoft.com
Sincerely,
Header
It causes an error when selecting it or changing format options. Lets say if I wanted to change the font, it would throw an error:
http://www.rattlesoft.com/Error_Exception.PNG
Re: [2005] RichTextBox / Error
At first glance your code looks ok, as a quick test put;
MessageBox.Show(FormatFont.SelectedItem.ToString)
just before the line where you show the error. What is the result from that when the error occurs? (I haven't tried it but I'm wondering whether you should be checking for FormatFont.Items.Count > 0 And FormatFont.SelectedIndex >= 0 instead of Not FormatFont.SelectedItem Is Nothing)
Re: [2005] RichTextBox / Error
Quote:
Originally Posted by Bulldog
At first glance your code looks ok, as a quick test put;
MessageBox.Show(FormatFont.SelectedItem.ToString)
just before the line where you show the error. What is the result from that when the error occurs? (I haven't tried it but I'm wondering whether you should be checking for FormatFont.Items.Count > 0 And FormatFont.SelectedIndex >= 0 instead of Not FormatFont.SelectedItem Is Nothing)
The message reports the selected item which in this case was "Arial". The FormatFont object is a combo box item, at least derived from the combo box.
The error still fires when I add those 2 if statements.
Re: [2005] RichTextBox / Error
I believe the problem is with this: formSoftware.RTFOBject.SelectionFont.Size
I added a message box that stated the size of the selected font and it through and error.
VB Code:
Dim f As Font = New Font(FormatFont.SelectedItem.ToString(), formSoftware.RTFObject.SelectionFont.Size)
Change to:
VB Code:
Dim f As Font = New Font(FormatFont.SelectedItem.ToString(), "12")
It works fine, but it doesn't solve the problem which is that the size should stay the same.
Re: [2005] RichTextBox / Error
What is RTFObject defined as? (eg. is it an Object, Control, Component?)
Re: [2005] RichTextBox / Error
RTFObject is a RichTextBox (Its not actually a control). I have 2 RTF boxes that when focused, set RTFObject to themselves.
Re: [2005] RichTextBox / Error
So you do define RTFObject like this?
Code:
'At top level
Dim RTFObject As RichTextBox
'In the sub/function level
RTFObject = RichTextBox1
'Create a new selection font, keeping the existing size
Dim f As Font = New Font(Me.Font.FontFamily, Me.RTFObject.SelectionFont.Size)
'Use the new font for the RTFObject
RTFObject.SelectionFont = f
This works ok for me. Without seeing your code, I would guess your not declaring RTFObject at the top (Class) level.