[b]What is the [color=\"Blue\"]RichTextBox Control[/color]?[/b]
[i]The [color=\"blue\"]RichTextBox control[/color] is a control which can read .rtf files and display them properly, unlike the basic TextBox control. You can also add color and images to this type of textbox also, unlike the basic TextBox control.[/i]
Now that we have that covered, let\'s jump right in. ~ First, let\'s actually get the [color=\"Blue\"]RichTextBox Control[/color] on our toolbox list of components.
[color=\"purple\"]1.) Right-click on the toolbox and select \"[b]Components[/b]\"
2.) Scroll down near the bottom/middle and find \"[b]Microsoft Rich TextBox Control 6.0 (SP4)[/b]\"
3.) Check it and then click \"[b]Apply[/b]\" and then \"[b]OK[/b]\"
4.) If everything went \'ok\' you should now have a [/color][color=\"Blue\"]RichTextBox Control[/color][color=\"Purple\"] ([img]http://img95.exs.cx/img95/6712/RTB.png[/img]) on your toolbox
Now go ahead and add the [color=\"Blue\"]RichTextBox Control[/color] to your form with a pretty good size to it and add a textbox underneath that with a command button somewhere and set the command button\'s default property to \"True\". You should end up with [i]something[/i] like this:
[img]http://img44.exs.cx/img44/3566/RTB1.png[/img]
Now lets add some code to this project. In the [b][color=\"red\"]Private Sub Command1_Click()[/color][/b] event, add this code:
Visual Basic Code
Public Sub Command1_Click()
If (Len(Text1.Text) > 1) Then
\'Adding The Nickname
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelBold = True
RichTextBox1.SelColor = QBColor(1)
RichTextBox1.SelFontName = \"Arial\"
RichTextBox1.SelFontSize = \"10\"
RichTextBox1.SelText = \"Josh: \"
\'Adding Text1.Text After The Nickname
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelBold = False
RichTextBox1.SelColor = QBColor(2)
RichTextBox1.SelFontName = \"Arial\"
RichTextBox1.SelFontSize = \"10\"
RichTextBox1.SelText = Text1.Text & vbCrLf
\'Clear the TextBox
Text1.Text = \"\"
End If
End Sub
If (Len(Text1.Text) > 1) Then
\'Adding The Nickname
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelBold = True
RichTextBox1.SelColor = QBColor(1)
RichTextBox1.SelFontName = \"Arial\"
RichTextBox1.SelFontSize = \"10\"
RichTextBox1.SelText = \"Josh: \"
\'Adding Text1.Text After The Nickname
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelBold = False
RichTextBox1.SelColor = QBColor(2)
RichTextBox1.SelFontName = \"Arial\"
RichTextBox1.SelFontSize = \"10\"
RichTextBox1.SelText = Text1.Text & vbCrLf
\'Clear the TextBox
Text1.Text = \"\"
End If
End Sub
Okay.. Now that we have all of this added, let me explain everything step-by-step.
[b][color=\"green\"]If (Len(Text1.Text) > 1) Then[/color][/b]
This means, \"If the length of the text in Text1 is greater than ONE, then do the following code
[b][color=\"green\"]RichTextBox1.SelStart = Len(RichTextBox1.Text)[/b][/color]
This is saying that we want to start our colored text at the end of everything that is in the [color=\"blue\"]RichTextBox Control\'s[/color] contents.. This is why we bring in [color=\"green\"]Len(RichTextBox1.Text)[/color] because it will return where to start, which is at the end of it all.
[b][color=\"green\"]RichTextBox1.SelBold = True[/b][/color]
This tells VB to make the text bold we are about to enter in the [color=\"blue\"]RichTextBox[/color]
[b][color=\"green\"]RichTextBox1.SelColor = QBColor(1)[/b][/color]
This tells VB to make the color navy blue, or QBColor(1).. (QBColor(1) = Navy Blue)
[b][color=\"green\"]RichTextBox1.SelFontName = \"Arial\"
RichTextBox1.SelFontSize = \"10\"[/b][/color]
This tells VB to make our font Arial size 10
[b][color=\"green\"]RichTextBox1.SelText = \"Josh: \"[/b][/color]
And finally, this is the text we are adding to our [color=\"blue\"]RichTextBox[/color], which is in fact \"Josh:\"
I think you can figure out the rest of the things that I\'ve included at the end..
[img]http://img78.exs.cx/img78/4075/RTB2.png[/img]
That is basically the workings of [color=\"blue\"]RichTextBox Control[/color].. Pretty simple eh? Sometimes I wonder why I was having such a hard time with it
If you have any questions, please feel free to PM me, or leave a post here
~Josh


