473,800 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RichTextBox Colors

Hi, I have some difficulties when adding text to a
(multiline)rich textbox, to change the color of that line only.
Changing colors on parts of text you want, need to be selected to
change color. So I need to create a code that selects the text I just
added to the richtextbox for a very short period so the user doesn't
notices.
Jul 17 '05 #1
3 11743
Where Start1 is the offset of the first character in the line:

With RTB
.SelStart = Start1
.Span vbCr, True, True '-- selects line up to carriage return..
.SelColor = 255 '-- [long color value - in this case
red.]
.SelLength = 0 '-- de-select line
End With
--
--
AttiDude <at************ ***@hotmail.com > wrote in message
news:pc******** *************** *********@4ax.c om...
Hi, I have some difficulties when adding text to a
(multiline)rich textbox, to change the color of that line only.
Changing colors on parts of text you want, need to be selected to
change color. So I need to create a code that selects the text I just
added to the richtextbox for a very short period so the user doesn't
notices.

Jul 17 '05 #2
Ok I've got now:

Private Sub Command1_Click( )
start1 = Len(RichTextBox 1.Text)
RichTextBox1.Te xt = RichTextBox1.Te xt & Text1.Text
With RichTextBox1
.SelStart = start1
.Span vbCr, True, True
.SelColor = 255
.SelLength = 0
End With
End Sub

This way the richtextbox always makes the last added text red. So if I
add a new text the old text turns black again.

Is there a way to keep the previous text the curremt color?
On Sat, 10 Apr 2004 15:13:52 GMT, "mayayana"
<ma************ @mindZZspring.c om> wrote:
Where Start1 is the offset of the first character in the line:

With RTB
.SelStart = Start1
.Span vbCr, True, True '-- selects line up to carriage return..
.SelColor = 255 '-- [long color value - in this case
red.]
.SelLength = 0 '-- de-select line
End With
--


Jul 17 '05 #3
> RichTextBox1.Te xt = RichTextBox1.Te xt & Text1.Text

You don't want to use the above line because that replace all the current
text (colors, bolding, etc.) with the Text (which is not formatted, Text is
just the characters) already in the RichTextBox plus those characters in the
regular TextBox. Anyway, the proper (read... fastest) way is to "insert" the
new text into the location of the text cursor. You do that by assigning
(only) the new text to the SelText property. If you first change the
SelColor property, then the newly inserted text will be that color. However,
you must remember to set the SelColor back to the color it had before you
changed it. Give this code a try instead of what you posted.

Private Sub Command1_Click( )
Dim CurrentColor As Long
With RichTextBox1
CurrentColor = .SelColor
.SelColor = vbRed
.SelText = Text1.Text
.SelColor = CurrentColor
End With
End Sub

Note that this will insert the text in the regular TextBox at the current
text cursor location, wherever that might be. If you want it to always be
added to the end of the current text, then add this line somewhere IN FRONT
OF the .SelColor=vbRed line (but after the With statement).

..SelStart = Len(.Text)

Rick - MVP
"AttiDude" <at************ ***@hotmail.com > wrote in message
news:ds******** *************** *********@4ax.c om...
Ok I've got now:

Private Sub Command1_Click( )
start1 = Len(RichTextBox 1.Text)
RichTextBox1.Te xt = RichTextBox1.Te xt & Text1.Text
With RichTextBox1
.SelStart = start1
.Span vbCr, True, True
.SelColor = 255
.SelLength = 0
End With
End Sub

This way the richtextbox always makes the last added text red. So if I
add a new text the old text turns black again.

Is there a way to keep the previous text the curremt color?
On Sat, 10 Apr 2004 15:13:52 GMT, "mayayana"
<ma************ @mindZZspring.c om> wrote:
Where Start1 is the offset of the first character in the line:

With RTB
.SelStart = Start1
.Span vbCr, True, True '-- selects line up to carriage return..
.SelColor = 255 '-- [long color value - in this case
red.]
.SelLength = 0 '-- de-select line
End With
--

Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
10741
by: Scott | last post by:
I need to have a RichTextBox that displays various text (in color), but the user cannot highlight or edit the text in anyway, With a regular textbox, I can set .Enabled=False and that does exactly what I want, but with the RichTextBox, setting .Enabled=False turns the box grey, and I need it to stay on the BackGround color....labels won't do, as I need individual words to be different colors. Any Ideas? Scott
2
2237
by: RobKinney1 | last post by:
Hello and thank you for reading this post. I have a RichTextBox. I need to select text inside for a search feature. Easy enough... right? Well apparently from the .NET help and everything from the net, there is nothing describing how to do a top level select that I can find (ie like how to select or highlight programitcally like a user highlights text from any window). Here is my code:
2
1925
by: Ludwig | last post by:
Hi, thanks to the insight that Kevin Spencer gave me concerning my regular expressions question from a few days ago, I managed to create a first version of my (free) Highlighter RichTextBox control. In short: it highlights portions of text in specified (fore- and background)colors, with a specified parser. I found a number of controls on the net, but all of them had some problems: mostly performance issues with larger texts and...
1
2368
by: gazelle04 | last post by:
I'm trying to use the "RichTextBox" control so that I can have a text box where you can format the selected text's font, size, and colors but when I insert that Active X control it gives an error "Microsoft Access Does Not support this Active X control". I'm using a MS Access 2003 in the office. How can I use that control.
1
1435
by: plonk | last post by:
Hi I'm having a small problem with a vb.net application (Visual Studio 2005) I'm trying to insert the contents of a Richtextbox.text into the body of an email. It all works fine, except when I open the email, all the carriage returns and linefeeds are stripped out and all the text appears on one line.
2
910
by: SeasCommander | last post by:
When I append data to my richtextbox I use selectioncolor to set the color of that block of text. The problem with this, is if the user is selecting as well. If my sub is called, the following executes: with myrichtextbox .selectioncolor = mycolor .appendtext(mytext) end with
1
3264
by: roucha | last post by:
I have created a chat program, and i want the usernames to be a different color then the other words in the richtextbox that i have. i have googled this and i did not find any suitable answer. Please help. -thanks
4
13492
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a multiline RichTextBox that I use for data logging. I'm concerned about how the AppendText method reacts when over time the maximum number of characters have been added. Do the oldest characters it contains start rolling off the top into the bit bucket, does it simply start silently ignoring appends until some characters, are deleted, or does some kind of exception get thrown? I've heard numerous opinions on what the...
0
2205
by: pzero24 | last post by:
I am trying to add a color table to the RTF of my RichTextBox control when I instantiate the control. The problem is that the color table will not stay there. The only time it stays is if I have text specified in the RTF that is formatted with one of the codes in the color table. That won't work because I don't want text in the control yet. Here is the code and the RTF and the RTF it displays after the line runs: ...
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.