none
What's the difference between Rich Text Boxes and Normal Text Boxes?

    Question

  • Hello,

    For those of you who don't know (like me), this is for you.

    What the hell is the difference between a rich text box and an ordinary text box?

    This is for all of you who don't know the answer and SOMEBODY HELP!!!

    Saturday, October 21, 2006 11:38 PM

Answers

  • ALOT

    richtextbox allows you to format text, open RTF formatted documents and view them as well as saving into those formats. Textboxts you cant really format them, its just only one font or 1 color or whatever, with an RTB you can format selected text or color certain text, change the font of text etc....

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx

    its more advanced than a plain simple textbox

    you can also tell it to detect url links automatically, a textbox doesn't do this. It's pretty much just like wordpad, if you have used it in Windows. You can create an entire rich text editor using the richtextbox control.

    you can select text, insert images, change fonts, change colors, load and save richtext formats or plain text formats - you can't do it with a textbox except for the fonts but even then you can only have 1 font applied to on a textbox. You can also I believe find text in the richtextbox and a textbox does not have this feature

    Saturday, October 21, 2006 11:53 PM
  • A simple TextBox can display text without or less formatting i.e it can display all of its Text in same formatiing. Like Bold, Italic Uderline or combination. You can give it fore color and also change font. That's it!

    On the other hand, RichTextBox facilitatets us to format different parts of text differently. Like 1 Area of text is bold other is normal while another is Bold + Italic+ Underline. You can alo put bullets in RichtextBox, Also set Fore and Background color of text. Also RichTextBox can display tables while Textbox can't. So there are many scenerios where you do need this type of formatting and a simple TextBox is of no use.

    Exact examples of these 2 are Notepad (TextBox) and Wordpad (RichTextBox).

    Open both the applications and play with different options. You'll know what is possible with RichtextBox which cant be done with TextBox.

    Best Regards ,

    Saturday, October 21, 2006 11:55 PM
  • everything is mentioned in the link given :-)

    Example of aligning the text.

  • select it then:

       this.theRichTextBox.SelectionAlignment = HorizontalAlighnment.Center; // (or Left or right)

     

    Coloring...select the text then:

    this.theRichTextBox.SelectionColor = Color.yourColor;

    you can also use SelectionBackColor to color the backcolor of the font

    Selecting text uses the SelectionStart property and the SelectionLength property, or you can use the Select method which takes in the index to start selecting from and the length you want to select for.

    As for number, you would have to do this yourself, its not a built in feature of the RTB.

    As for bulleting, there is a property called SelectionBullet which you can set to true, so select the text you want to bullet then set this property to true. Pressing enter on the next line proceeds to still make it in bulleting mode

    for URL's, set the DetectURLs property to true

    As for the Bold/Italics etc..., use the SelectionFont and create a new font and one of the overloads allows you to use the FontStyle.

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionfont.aspx

Sunday, October 22, 2006 1:07 AM

All replies

  • ALOT

    richtextbox allows you to format text, open RTF formatted documents and view them as well as saving into those formats. Textboxts you cant really format them, its just only one font or 1 color or whatever, with an RTB you can format selected text or color certain text, change the font of text etc....

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.aspx

    its more advanced than a plain simple textbox

    you can also tell it to detect url links automatically, a textbox doesn't do this. It's pretty much just like wordpad, if you have used it in Windows. You can create an entire rich text editor using the richtextbox control.

    you can select text, insert images, change fonts, change colors, load and save richtext formats or plain text formats - you can't do it with a textbox except for the fonts but even then you can only have 1 font applied to on a textbox. You can also I believe find text in the richtextbox and a textbox does not have this feature

    Saturday, October 21, 2006 11:53 PM
  • A simple TextBox can display text without or less formatting i.e it can display all of its Text in same formatiing. Like Bold, Italic Uderline or combination. You can give it fore color and also change font. That's it!

    On the other hand, RichTextBox facilitatets us to format different parts of text differently. Like 1 Area of text is bold other is normal while another is Bold + Italic+ Underline. You can alo put bullets in RichtextBox, Also set Fore and Background color of text. Also RichTextBox can display tables while Textbox can't. So there are many scenerios where you do need this type of formatting and a simple TextBox is of no use.

    Exact examples of these 2 are Notepad (TextBox) and Wordpad (RichTextBox).

    Open both the applications and play with different options. You'll know what is possible with RichtextBox which cant be done with TextBox.

    Best Regards ,

    Saturday, October 21, 2006 11:55 PM
  • ok then,

     thanks,

    just a few more questions related to RTF boxes (mainly focusing on one language though), especially with formatting options.

    Apart from the font dialog in C#, how do you:

    Bold the words

    Italic the words

    Underline the words

    And also in C# how do you:

    Text Align Left

    Text Align Centre

    Text Align Right

    Colour the RTF

    Colour the font

    • Bullet point the RTF
    1. Number the font

    Work URL font

     

    Sunday, October 22, 2006 12:58 AM
  • everything is mentioned in the link given :-)

    Example of aligning the text.

  • select it then:

       this.theRichTextBox.SelectionAlignment = HorizontalAlighnment.Center; // (or Left or right)

     

    Coloring...select the text then:

    this.theRichTextBox.SelectionColor = Color.yourColor;

    you can also use SelectionBackColor to color the backcolor of the font

    Selecting text uses the SelectionStart property and the SelectionLength property, or you can use the Select method which takes in the index to start selecting from and the length you want to select for.

    As for number, you would have to do this yourself, its not a built in feature of the RTB.

    As for bulleting, there is a property called SelectionBullet which you can set to true, so select the text you want to bullet then set this property to true. Pressing enter on the next line proceeds to still make it in bulleting mode

    for URL's, set the DetectURLs property to true

    As for the Bold/Italics etc..., use the SelectionFont and create a new font and one of the overloads allows you to use the FontStyle.

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.richtextbox.selectionfont.aspx

Sunday, October 22, 2006 1:07 AM
  • Yes thanks for that, most of it worked correctly, but I have to try something else with tohse things. I'll get back to you on the Bold, Italic, Underline and the URL properties but otherwise, this thread's been really excellent! Thank you!
    Monday, October 23, 2006 8:27 PM
  • no worries! :-)
    Monday, October 23, 2006 8:47 PM
  •  

    Public Class DocumentPrinting

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            RTB.Text = "hello" & vbCrLf

            RTB.Select(0, 5)

            Dim newFontStyle As System.Drawing.FontStyle

            newFontStyle = FontStyle.Bold OR FontStyle.Italic

            Dim font1 As New Font("Verdanda", 8)

            RTB.Font = font1

            RTB.SelectionAlignment = HorizontalAlignment.Right

            RTB.SelectionFont = New Font( _

            font1.FontFamily, _

            font1.Size, _

            newFontStyle)

        End Sub

    End Class

    :)

    Thursday, October 26, 2006 12:37 AM