|
-
Apr 17th, 2007, 11:55 AM
#1
Thread Starter
Hyperactive Member
[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:
-
Apr 17th, 2007, 02:42 PM
#2
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)
-
Apr 17th, 2007, 03:11 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] RichTextBox / Error
 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.
-
Apr 17th, 2007, 03:13 PM
#4
Thread Starter
Hyperactive Member
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.
Last edited by tylerm; Apr 17th, 2007 at 03:17 PM.
Reason: More information
-
Apr 17th, 2007, 04:39 PM
#5
Re: [2005] RichTextBox / Error
What is RTFObject defined as? (eg. is it an Object, Control, Component?)
-
Apr 17th, 2007, 04:45 PM
#6
Thread Starter
Hyperactive Member
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.
-
Apr 17th, 2007, 05:39 PM
#7
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.
Last edited by Bulldog; Apr 17th, 2007 at 05:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|