Results 1 to 7 of 7

Thread: [2005] RichTextBox / Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    [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:


  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    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:
    1. Dim f As Font = New Font(FormatFont.SelectedItem.ToString(), formSoftware.RTFObject.SelectionFont.Size)

    Change to:
    VB Code:
    1. 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

  5. #5
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] RichTextBox / Error

    What is RTFObject defined as? (eg. is it an Object, Control, Component?)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Alaska
    Posts
    435

    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.

  7. #7
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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
  •  



Click Here to Expand Forum to Full Width