473,322 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 11020
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kangoo | last post by:
Hi, I'm trying to remove the last charater in a richTextBox. I though richTextBox.Text.Remove(richTextBox.Text.length-1, 1); would work, but it does nothing (eg richTextBox.Text += "some new...
2
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is...
2
by: Hendrik | last post by:
Hi I have searched extensively for help on inserting text at the position of the mouse pointer in a text box as the final step of drag and drop process What I have come with is listed below - the...
5
by: Alvo von Cossel I | last post by:
hi, i have a word processor with a richtextbox in the center of the screen. if you paste an image into the richtextbox, it will appear. however, with my openfiledialog, only some text will...
1
by: gabe | last post by:
I am looking for a way to mimic some of the functionality of a web page without writing html (or I am looking to someone to point out something really obvious that I am over looking) Currently I...
2
by: Clark Stevens | last post by:
Hi. This should be so easy, but I don't get it. Let say I have RichTextbox1 and I want to insert some text at the current insertion point, or at the beginning of selected text (if there is any). ...
3
by: michael sorens | last post by:
The documentation for the RichTextBox is sketchy at best. I want to do a very simple task but I cannot find information on this. I am using a RichTextBox as an output window. Some text I want to...
1
by: farrukhqadri786 | last post by:
Hi! I have an imageList and a richtextbox in a C# form. I want to insert image from imageList into a richtextbox. I have found the following code on net but it does'nt work. ...
0
by: ajithmanmadhan | last post by:
hi pls help me out in inserting text into a richtextbox. the situation is like this:: i want to insert a string say "hello" at a particular location in the rich textbox. The particular...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.