469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

Inserting text into a RichTextBox

I have a RTF control on a form and want to insert text programmatically. I
thought it would be easy but it does not turn out that way. Can someone
refer me to an Internet article that covers this action. When I insert the
text, the formatting for the other content of the control is lost.

In summary, I want to add the current date and time to a RTF control while
maintaining the existing appearance.
Nov 21 '05 #1
5 10770
"genojoe" <ge*****@discussions.microsoft.com> schrieb:
In summary, I want to add the current date and time to a RTF control while
maintaining the existing appearance.


\\\
With Me.RichTextBox1
.Select(100, 0)
.SelectedRtf = ... ' Or 'SelectedText'.
End With
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
I am at a loss regarding how to use this advise.

"Herfried K. Wagner [MVP]" wrote:
\\\
With Me.RichTextBox1
.Select(100, 0)
.SelectedRtf = ... ' Or 'SelectedText'.
End With
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
"genojoe" <ge*****@discussions.microsoft.com> schrieb:
I am at a loss regarding how to use this advise.
\\\
With Me.RichTextBox1
.Select(100, 0)
.SelectedRtf = ... ' Or 'SelectedText'.
End With
///


Simply paste the text into the text-editor window. A richtextbox called
'RichTextBox1' must exist and you will have to replace 100 with the insert
position and the ellipsis with the text to insert.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
Thank you.
I finally came up with the following code. I paste it here in case anyone
else ever reads this sequence. Too bad Microsoft did not show something like
this in Help for SelectedRtf. Its so simple; all you got to do is try it.

Debug.WriteLine(Me.rtfUser.Text) 'Returns "Date: . Thank you"
Me.rtfUser.Select(6, 0)
If Me.chkMakeBold.Checked Then
Me.rtfUser.SelectedRtf = "{\rtf1\an......\uc1\b\f0\fs20 5-15-05
\b0}"
Else
Me.rtfUser.SelectedText = "5-15-05"
End If

I center truncated the SelectedRtf text.

Nov 21 '05 #5
"genojoe" <ge*****@discussions.microsoft.com> schrieb:
I finally came up with the following code. I paste it here in case anyone
else ever reads this sequence. Too bad Microsoft did not show something
like
this in Help for SelectedRtf. Its so simple; all you got to do is try it.

Debug.WriteLine(Me.rtfUser.Text) 'Returns "Date: . Thank you"
Me.rtfUser.Select(6, 0)
If Me.chkMakeBold.Checked Then
Me.rtfUser.SelectedRtf = "{\rtf1\an......\uc1\b\f0\fs20
5-15-05
\b0}"
Else
Me.rtfUser.SelectedText = "5-15-05"
End If


You could use the 'Select' method to insert the selected text and make it
bold by assigning a bold font:

\\\
Me.RichTextBox1.SelectionFont = _
New Font(Me.RichTextBox1.SelectionFont, FontStyle.Bold)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by kangoo | last post: by
2 posts views Thread by Martin Dew | last post: by
5 posts views Thread by Alvo von Cossel I | last post: by
2 posts views Thread by Clark Stevens | last post: by
3 posts views Thread by michael sorens | last post: by
1 post views Thread by farrukhqadri786 | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.