472,371 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 10943
"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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.