Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Richtextbox And Adding Text

At the moment I have this code in a menu to add a marquee tag:

VB Code:
main.RichTextBox1.Text = main.RichTextBox1.Text & vbCrLf & "<marquee></marquee>"

But the problem is it adds it to the end.

Is there a way of making it add the tag where the curser is rather than at the end?

Thank you

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Adding Text To RichtextBox From File
I know that the RTB has a .LoadFile method to load rtf formatted text into the control. However, I have a custom text file that contains several settings (ex. THIS=That) and then at the end BODY=<rtf text here>, BODY being the body of an e-mail message.

I cannot seem to re-load the rtf formatted text into the control. I tried both .Text and .TextRTF = <string of rtf from the file> but I get all of the rtf formatting garbage on-screen.

Is there a way to load the RTB control without using .LoadFile?

Keep The Color Of Richtextbox.text On Copy To Another Richtextbox
So, i have 2 richtextbox controls and the text in one of them is colored with different colors (per words like vb editor).When I copy the text to another richtextbox, I lose the colors.How can I keep the colered words?

Does anybody experienced this?


Adding RichTextBox On The Fly

I have an SSTab control which initially has one tab, and on that tab is a richtextbox control called txtCode (array index 0).

When the user decides to add a new page, I need to add a new tab to the SSTab control (I've done this part already), and also add a new txtCode RichTextBox control on the new tab.

How do I do that?

Adding Pictures In Richtextbox
i've seen Volte-Face tutorial on richtext box and it says to add pictures use

RichTextBox1.OLEObjects.Add , , , "C:My Documents1.gif"

but id doesnt seem to work

Adding Lines To RichTextBox 6.0
I would assume this is a easy question, and I'm just being stupid about something...

I'm inputing lines from a text file into a Rich Text Box, and want them to appear with the same line breaks that are present in the text file. I've tried adding chr(13) to the end of each input string from the text file, and that sort of works, but it adds a full space between each line, instead of just a single carriage return.

Any ideas? Should I be using another ascii value? (even though I hope I'm not cause the box later re-saves to a file and looks for chr(13)'s to make spaces in the text file)
I'm not too famililar with RichTextBox, so maybe I'm doing something wrong there.

Thanks for any help,


Adding Pictures To A Richtextbox?
Is there a way to replace certain text in a rich text box with a picture? I remember seeing a tutorial on planetsourcecode, but they are having problems and all Zip files are gone, so I can't get it.

Adding Images To RichTextbox
anyone know how to add images to a richtextbox ???

Adding RichTextBox At Run Time
Hi everyone,

How do I add Richtextbox at runtime? I keep getting this error when i do it this way:

Set eRichTextBox = frmProject.Controls.Add("RichTextBoxLib.RichTextBox", "ENewBox")
eRichTextBox.Visible = True
eRichTextBox.Width = 6495
eRichTextBox.Height = 3975

Error message : Run time 711. Invalid class string. Looking for object with ProgId: RichTextBoxLib.RichTextBox

Am I missing a library? If so, where can i find that library?

Thanks for helping!

Adding " To A RichTextBox
I tried this code

RichTextBox1.Text = "Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long" & vbCrLf

BUT I got a compile time error (end of statement)
how can I add ( " ) to the RichTextBox1

Adding Date And Time To Richtextbox
When the user clicks on add date or time it does enter it, but any text in the rtb is automatically deleted.
How to I write the code to add either the date or time to where the cursor is without affecting the text already in the boX?

rtb1.TextRTF = Time

Richtextbox And Going Horizontal And Not Adding A New Line?
I'm working on my text editor and I've been trying to figure out how come the text when I enter doesn't keep going, it automatically creates a new line when i get to the right side of the form. Does anyone know how i can stop this ? A good example of what i'm trying to do is like how notpad will allow it's text to go and keep going to the right triggering the horizontal scroll bar.


Richtextbox And Going Horizontal And Not Adding A New Line?
I'm working on my text editor and I've been trying to figure out how come the text when I enter doesn't keep going, it automatically creates a new line when i get to the right side of the form. Does anyone know how i can stop this ? A good example of what i'm trying to do is like how notpad will allow it's text to go and keep going to the right triggering the horizontal scroll bar.


* * * *it sorry for double posting this i didn't mean to i thought the browser got stuck.

Adding A New Forms Containing A RichTextBox At Runtime?

I am currently developing an application which will interact with MS Word. When the user clicks on 'Get Word Documents' I need to be able to dynamically create the same number of forms as there are MS Word documents.

The new forms in VB will also each need to contain a RichTextBox. Is this possible?

Any feedback much appreciated



Problem With Adding A Picture To RichTextBox...
I am using the following method to put a .bmp in a rtb.

rtbPicture.OLEobjects.add , , app.path & "a.bmp"

(can't remember if it is oleobject or oleobjects...)

anyway, here is my inserts the picture in to the rtb fine, but sometimes it opens paint with it and it puts a dotted box around the picture like you could drag it or resize do i get around this?


Trouble With Adding OLE Object To RichTextbox
I have been struggling with adding an OLE object in a RichTextbox. My problem is that I want to add it as an icon instead of opening the application the object is associated with. This is what I am currently doing...

1. I add the object using the Richtextbox.OLEobjects.Add method
2. I set the OLEObjects.Item.DisplayType to show just an icon

This works, but first it opens the application associated with the file when the add method is called. Then the object is turned into an icon. This is somewhat OK for things like Word or Excel files where the application opens up inside the RichText box, but it is terrible for files like Access file that open up outside of the Richtextbox because these applications are still open after the object has been changed to an icon.

There are a few other issues as well. First, the icon that eventually shows up has no caption. I can not for the life of me figure out how to add one. There does not seem to be any property to set or parameter to pass to make this happen.

If anyone can help, I would greatly appreciate it.


Adding Graphics To A Richtextbox Control
Hi, all,

How can I write code to place a known (or dynamically selected) image onto a specific position in a richtextbox control, in between adding and formatting chunks of text?

And once I do that, how can I go back and grab it afterwards if I need to manipulate it further?

If I use the LoadFile method to load a Word document containing the graphics, how do I rearrange my code which formats the other chunks of text that follow as far as SelStart and SelLength are concerned?

My code for generating the RichTextBox contents resides in a cmdbutton. This works fine when invoked for the first time on new records, but on subsequent clicks, the output acquires a wrong format in that it appears all underlined and bold and in the same fontsize. I am setting the relevant format options prior to inserting any text segment, so I don't understand what could be causing this problem.

Any one who can help?


Experience is a bad teacher for its exams precede its lessons.

Edited by - GoodGuy on 8/21/2005 11:51:42 PM

[?] Adding OLEObjects In RichTextBox. A Problem.
Hi friendz,

My purpose is to add OLEObjects (like bmp, doc, exe, dll etc.) to RichTextBox control. I want these objects to be displayed as small icons in the RichTextBox.

When I add the OLEObject to the RichTextBox using the following code, it embeds the object, but simultaneously, it also launches the application. e.g. If I add a txt file, it opens it in notepad, and if I add an exe it runs the exe (though it doesn't open the mspaint for bmp).

The biggest problem will arise if I try to add a .reg file. It will cause a havoc by changing the local registry.

The code I use is :

private Sub cmdAddObject_Click()

Dialog1.ShowOpen 'common dialog

If Dialog1.FileName = "" then Exit Sub

RText2.OLEObjects.Add , , Dialog1.FileName

'to hide the application that created the object:

RText2.OLEObjects(0).DoVerb vbOLEHide

End Sub

A help in this driection will be appriciated.

Thanks and regards,

- Mridul.

Adding TextRTF Without =&gt; RichtextBox.textRTF = RichTextBox.textRTF&&newpart RESOLVED
I'm making a project that uses Richtextboxes

When I want to add new code to my project I do it this way :

previous = RichTextBox1.TextRTF
leftside = Left(previous, Len(previous) - 6) 'removing the "par }" (will be added again later on)
RichtextBox1.textRTF = leftside & Newcodes & "par }"

This takes a lot of time when I use a lot of pictures because all previous data needs to be re-evaluated by the RichTextBox.

When NORMAL PEOPLE add text to a textbox they do it this way ...

RichtextBox.seltext = NewText

But this can't help me because I'm not adding text.... I'm adding RTF-codes (that can not be done with the RichTextBox standard properties).

But does somebody know how I can add RTFtext without having to read all previous RTFtext ?

Adding Multiple Images To A Richtextbox Control

I am using a richtextbox control and I want to add images(.bmp files) to the richtextbox. Images like smileys. How can I do this I need this on an emergency basis plz help

Take care & Luv all u coders


Prevent Flickering When Adding New Message In RichTextbox Control
There is no need to highlight the code before setting the color, which is probabaly causing the fickering.

New text with new color can be added like this without affecting exisiting text.

'Set colours
'Richtextbox1.SelText = "New Text"

And modified:

Public Function DisplayTrace(ByVal sMsg As String, Optional ByVal ErrorLevel As Integer = 0, Optional bLineFeed As Boolean = True)
'following the error level the color is changed for the added line

'first add the text
If bLineFeed Then
sMsg = sMsg & vbCrLf
End If

RichTextBox1.SelStart = Len(RichTextBox1.Text)

'set it's color
Select Case ErrorLevel
Case 1
RichTextBox1.SelColor = vbBlack
Case 2
RichTextBox1.SelColor = &H80000001
Case 3
RichTextBox1.SelColor = vbRed
End Select

RichTextBox1.SelText = sMsg
RichTextBox1.SelStart = Len(RichTextBox1.Text)

End Function

Replacing Strings In RichTextBox Control W/out Adding To File Length
Is there a way to insert text into a richtextbox control without increasing the length of the file?

I have a word document that serves as a fax sheet and I've converted it to .rtf so I can load it into an rtb control. I wrote some code that will take input from another form and write it to the rtfText on the control. I set selStart where I want the string to appear, I set selLength equal to length of the string, and I set selRtf equal to the string, which is the input from another form. This works, but I notice that the text below moves the number of characters I just added. This is bad because it effects the format of the document and it causes the document to print out a blank page. What can I do?

RESOLVED-Setting The Backcolor Of Selected Text In Richtextbox-highlight Text
Does anybody know how to change the backcolor of selected
text in a richtextbox. Not the background color of the whole richtextbox only the selected word-lines !

I use a richtextbox which uses some validation and if there is an error in the text i want to display the word in red backcolor.

do you have any tips of alternatives if i cant do this?
Moreover how do you underline the selected text.
i use rtf.selunderline but it does not work.


p.s. i search the forum and did not find any solution.

Save Text From RichTextBox In UTF (plain Text) ?
How do I save text from RichTextBox in UTF (plain text), to a file ?

Adding Text1.Text, Text2.Text&&Text3.text!
Hello, i have my Configuration file which is pretty simple file, openable with notepad, like txt.

I want to add text1.text in new line, text2.text in new line and text3.text in new line too. notice: in my attrib.cfg there alot of text, so i basically want to add all this at the end of file


Adding Text To Rich Textbox Without Changing Format Of Existing Text?
Hello all. This is my first time working with RTB's, and I'm having a little trouble getting started. I'm sure it's some little problem of syntax/semantics, but I can't figure it out. A little help would be greatly appreciated!

I have a RTB to which I am trying to add texts of different formats. When I add each string, the entire box text takes the most current format. This makes perfect sense to me, as I am essentially rewriting the ENTIRE textbox (I am using the ".Text = .Text & "NEWTEXT" format that I am accustomed to using for textboxes.

What am I doing wrong? Thanks!

VB Code:
'1.  Create a new form.'2.  Add a button named butGo.'3.  Add a RTB named rtbText.'4.  Cut & Paste the procedure below. Private Sub butGo_Click()Static Counter As IntegerCounter = Counter + 1With rtbText    Select Case Counter        Case 1: .Font.Size = 16                .Font.Bold = True                .Text = .Text & "This is a test..."        Case 2: .Font.Size = 12                .Font.Bold = False                .Text = .Text & "This is only a test!"        Case 3: .Font.Size = 6                .Font.Italic = True                .Text = .Text & "  Can you see me?"    End SelectEnd WithEnd Sub

Help With RichTextBox, How To Add Text?

how can I add text to a rich text box?

Private Sub Command1_Click()

If Text2.Text = "" Then
Exit Sub
End If

If Text1.TextRTF = "" Then
Text1.Text = "- " & Text2.Text
PutSomethingIn (Text2.Text)
Exit Sub
End If

If Text1.TextRTF <> "" Then
Text1.Text = "- " & Text2.Text & vbCrLf & vbCrLf
PutSomethingIn (Text2.Text)
Exit Sub
End If
End Sub

Public Sub PutSomethingIn(TheString As String)

Text1.TextRTF = Text1.Text & "{ Well hi there! 0}"

'this has to be at the end!
Text2.Text = ""
End Sub

I renamed my RTB to Text1, and I want to add text to it and format it. How can I do this? It won't work


Btw, anybody know of a good RTB tutorial i can read?

Richtextbox And Text Box?

In a form, I have one standard text box and one richtext box. the user can pick different text color when filling in the textbox, after that when it save, the content of the textbox will append into a locked richtextbox on the same form (to keep the history what or who entry to the textbox).

The problem is when append the text into the richtextbox. the color that set on the textbox is gone. how to keep the text color in the richtextbox?


Richtextbox Text
You can have your text keep going to the top and have the old text move to the bottom...

Private Sub rtbText_Change()
rtbText.SelStart = rtbText.SelLength
End Sub

Adding Text From A Text File To A Label Control
if I want to add text from a text file to a label control, can I do that?

Pointing To Text File And Adding A Line Of Text

I have been trying to add a line to a text file via the preview textbox which is on a different form I have tryed to do it like so also.

Print #1, ; frmCopy.textPreview.Text (which didnt work)

Could you please tell me where i am going wrong?

I can point to the file fine but it then highlights
Open (filFile1.Path & "" & filFile1.FileName) For Append As #1
in yellow and says the file is already open.

VB Code:
If (filFile1.FileName) = "sample.txt" Then    Open (filFile1.Path & "" & filFile1.FileName) For Append As #1    Print #1, ; textPreview.Text    MsgBox "added line to text file" End If     Exit Sub  End Sub

Text Box Text Adding Extra Space At End When Saving To DB
This is happening on only one out of about 20 forms that I have created...and I cannot pinpoint the reason for it...but would be interested in a possible solution.

I have appx. five text fields that are adding a space to the end of the string.

For example, I get some data like this: "myname "

See how there is a space at the end of the letter e? It is only occuring on this one form. Any ideas on how to get rid of this? Would a trim do the trick? Thanks in advance.

TempDyna("User_name") = ConWriteID
TempDyna("F_name") = TxtFName.Text
TempDyna("L_name") = TxtLname.Text
TempDyna("Buyer_cd") = TxtUserCode.Text
TempDyna("admin_yn") = chkCWadmin.Value
TempDyna("Term_id") = TxtTermId.Text
TempDyna("ofc_symbol") = TxtOfficeSymbol.Text
TempDyna.LockEdits = False

Adding Text To Textbox Without Deleting Previous Text
Hello All

I'm new here. Been programming in VB 6.0 for a while but i'm a beginner.

I'm writing a sort of calculator that puts the results in a textbox. But when i get a new result i just want to add it to the textbox, but it erases the previous answer.
I can use a listbox (addItem) but I have to be able to copy the selection in the result field and i can't do that in a listbox.

In short.

Everytime i get a new result it has to edit the textfield, not clear it and start all over again.

TextBox1.Text = "result...."
That's the code i'm using to put in the result.

Anyone know a solution to this ?
Thanx in advance.

Problem Adding Text To Existing Text In Field...

I need some help, as always, I currently have a table called 'notificationMessageTbl' and I have a TEXT field called 'userReadID' what I want to do is add text to the end of current text within the field using SQL

If I use the following code it just replaces the exsisting text with '12,' and does not append.

Code:UPDATE notificationMessageTbl SET userReadID = '12,'

Thanks in advance


Sending Text To Richtextbox
Hi! I use this line to write text in the richtextbox:
rt.TextRTF = rt.TextRTF & "{
tf1ansi  creardir: 0" & directorio & mivalor & vbCrLf & "}"

The thing is that I must use:
rt.TextRTF = "{
tf1ansi  creardir: 0" & directorio & mivalor & vbCrLf & "}"

to write the line, but if I want to add another line the old text will disappear and will be replaced by new text.
I thought that using:

rt.TextRTF = rt.TextRTF & "{
tf1ansi  creardir: 0" & directorio & mivalor & vbCrLf & "}"

Woluld preserve the old text but will clear the box and no text would be displayed.
Any ideas?

RichTextBox Text Selection
I am developing a report writer that uses "placeholders", such as <<NAME>>, using a RichTextBox (RTB). I can get <<NAME>> inserted into the RTB, with the NAME in a different colour to the << and >> through a command button. However, what I don't want users to be able to do, is to edit part of the <<NAME>> placeholder. They should be able to delete the whole placeholder, but not change it to, say, <<NAM>>. This would stop a function from replacing the placeholder with the name of the person. Is there any way to force the RTB control to select the whole placeholder if any part of it is clicked or the cursor alights on it? I want to avoid using icons/graphics/OLE objects for my placeholders if possible. I am using VB6 on top of an Access DB. Thank you in advance.

Richtextbox Not Accepting Text
I have a program that when I run it, it compares the results and then pastes it into a textbox.

Now the thing is, when I use a regular textbox, the text will show up.
When I use a RTB, then the text will not show up.

The code is something like,

code that compares data
text1 = text1 & "some strings of data" 'this is the regular textbox
rtbtext = rtbtext & "some strings of data" 'this is the richtextbox

What prevents data from being entered into the RTB?
Is there an option or property that needs to be set?
I can't find it if there is...


Richtextbox - Get Text Width

I am looking to size the width of a richtextbox to the width of the text inside it. I have tried using the TextWidth() function, but unfortunately that is far too inaccurate because the text inside the rtb varies in size,font ect.

Anybody know how I can grab the width of the text inside the richtextbox so that I may size the RTB accordingly?


Richtextbox Text Color
how do you change the text color in a richtextbox....?

I want to have five numbers colored black and the last number to be red.

I tried the following and it doesn't work


'Print out numbers
RichTextBox1.SelColor = vbBlack
RichTextBox1.Text = RichTextBox1.Text & A & " " & B & " " & C & " " & _
D & " " & E & " "
RichTextBox1.SelColor = vbRed
RichTextBox1.Text = RichTextBox1.Text & F & vbCrLf

RichTextBox And Selected Text
Okay. I'm having another newbie issue here.

I have a rtb (txtNotepad), a combobox (comboFonts), and a second combobox (comboFontSizes).

The problem I'm having is that when I select some text and then change the font or font size, the change won't take effect until I click the highlited text back in the RTB. And if I change the font and/or font size then highlight some text, the RTB changes to the new font as I select the text. Can somebody tell me where my problem lies? I'd be happy to post some code if necessary. Thanks in advance!

Highlighting Text In A RichTextBox

i would like to know whether it is possible to change the background colour of text within a richtextbox control, similar to it being highlighted?

a) blue writing with red highlight
b) red writing with blue highlight

if so, can anyone explain please explain how it is done.



Colouring The Text Of A RichTextBox
is this the only way to colour the text:

frmEditor.rtbDisplay.SelStart = 1
frmEditor.rtbDisplay.SelLength = Start - 14
frmEditor.rtbDisplay.SelColor = &H459008
this is very slow

but there must be a quicker way! vb compiler/c++ compiler is fast

do you know any faster method?


Appending Text To RichTextBox
I'd like to append several Access memo fields into a RichTextBox. Any thoughts how to do this? Normally, each time I write to the RichTextBox, it overwrites the previous text.

Text Color In Richtextbox
I set richtextbox.textRTF to the following:

ed255green0lue0;}{cf1 N}abc}

the text box displays N in red and the abc in black. which is what I expected.

however after this when I load the same content again all the charactes become red.

anyone know why is that?


Select Text In RichTextBox
I need to get an area of text from a RichTextBox. I need to be able to access the textbox like you would Mid a string. Select from where you start and how long for...


Replacing Text In A RichTextBox
In this post, VolteFace submitted the following code to replace RTF formatted text.

rtfText.TextRTF = Replace(rtfText.TextRTF, "[]7", "7 {cf1 ")
rtfText.TextRTF = Replace(rtfText.TextRTF, "[/]", "}")
I tried it, but VB5 enterprise cant seem to recognise 'Replace'.
Is this a VB6 or .Net only function, or some DLL call I need source code for?

How To Print The Richtextbox Text?
I'm trying to print the formated text that a richtextbox contains by using the printer object. The code that I am using is as follows:

dim x as printer

when I run this code :
there is an error in the line:
I get the following error messageit says that the object is not set

Please let me know the correct code for printing the formatted text that the richtextbox contains......

please help. Thank you.

How To Fill RichTextBox With Help-text?
Till now, I show the context-sensitive Help-text of a control via the ShowWhatsThis method and its WhatsThisHelpID. (The text is typed in a .hlp file)

How can I load that text into a RichTextBox instead?


Adjusting Text In A RichTextBox ??
Hi there.
I've picked up my VB6.0 programming after some months of "hibernating", and of course.... I've lost some skills in this period :-)

I have also searched the forums on this subject, and after reading 393 posts regarding "tabulator" and "RichTextBox", I could not find a solution for my problem. So I really hope that someone is able to help me out here.

What I need is some advice on how to adjust the text I'm putting into a RichTextBox.
All the data is coming from a database and I've got the connection to work.
The problem is getting the different text fields to appear in the right places in my RTB.

The data fields consists of different lengths, and this is what makes this a problem.
I have the fields of "id", "Ref", "Date", "Lastname", "Firstname", "Address" etc. etc.

I want these fields to appear in this way:

The header is like this:
id...Ref.....Date.......Lastname...................Firstname.......... .Address
(the periods . are just there to illustrate the space between the different fields, i didn't find any vB code that handles spaces when posting on this forum).

Because that the different fields have different lengths, I need to use some kind of tabulator function so each field is put in the exact correct place under each "field header".

Also I would like to have the id and Ref fields to be right aligned, the rest of the fields should be left aligned.

I hope I managed to explain my issue in a understandable way. If not, please tell me and I will revise my questions.


Dragging Text Into Richtextbox
Hello, i want my program to have a feature where they can drag a letter from a menu into the richtextbox, and that will automatically add that letter into the rich textbox. For example, the letters are special characters with accent marks on them. I want the user to be able to add one while typing something into the richtextbox. How would i do this??

Copyright 2005-08, All rights reserved