473,791 Members | 2,995 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing color in richtextbox multiple times goes wrong

Hi,

In my programm users can enter text which is added to a richtextbox.
Everytime a text is added, this text had get his own color.
The first 2 times it goes fine,
eg.

hallo (red)
hallo (yellow)
But when a third time a text is added with e.g. the color blue, the
first 2 gets the color red ??
Help what am i doing wrong
Here my piece of code:

Dim c As Color

If rbtrood.Checked Then
c = Color.Red
End If

If rbtgeel.Checked Then
c = Color.Yellow
End If

If rbtblauw.Checke d Then
c = Color.Blue
End If

With rtb
.Text &= rtbinvoer.Text
.SelectionStart = L
.SelectionLengt h = rtbinvoer.Text. Length
.SelectionColor = c
End With

L = rtb.Text.Length

Hope anyone can help me,

Thank already

Klaasjan

Nov 21 '05 #1
1 1403
Klaasjan wrote:
Hi,

In my programm users can enter text which is added to a richtextbox.
Everytime a text is added, this text had get his own color.
The first 2 times it goes fine,
eg.

hallo (red)
hallo (yellow)
But when a third time a text is added with e.g. the color blue, the
first 2 gets the color red ??
Help what am i doing wrong
Here my piece of code:
[snip]
With rtb
.Text &= rtbinvoer.Text
This is where the problem lies, my experiments have discovered. It
appears that you should never assign directly to the .Text property of
a RichTextBox - doing so erases ALL formatting information. Even this:

RichTextBox1.Te xt = RichTextBox1.Te xt

which looks like it will do nothing, actually has the side effect of
erasing ALL formatting information. Some might call this a bug, but not
me :)

In this particular instance the solution is easy: instead of
.Text &= rtbinvoer.Text


just do

.AppendText(rtb invoer.Text)

and you get your desired result. If you need to do more complex stuff,
eg adding text to somewhere other than the end of the existing text, I
recommend this thread:

<http://groups-beta.google.com/group/microsoft.publi c.dotnet.langua ges.vb/browse_frm/thread/22b088acbf67034 e>

and a bit of experimentation .

--
Larry Lard
Replies to group please

Nov 21 '05 #2

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

Similar topics

1
2585
by: vanvee | last post by:
Hi I have a user control that contains a RichTextBox in vb.net. In my program, I create multiple instances of this control (with the RichTextBox being in each one), that appear one above the other on a panel. The problem is that each control may have varying amounts of data, and so each RichTextBox (within each control) needs to size to fit the amount of text within that RichTextBox. I've tried multiplying the size of a single line...
3
1854
by: Sakharam Phapale | last post by:
Hi All, I am using a richTextBox control for text editing purpose. I have written following procedure which change the font style of richTextBox. Dim f as font = rtbData.selectionFont() rtbData.SelectionFont = New Font(f, f.Style + (IIf(f.Bold, FontStyle.Bold * -1, FontStyle.Bold)))
7
2975
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
0
1287
by: iwdu15 | last post by:
hi, im creating an instant messenger using TCP sockets, and everythings been fine until now. i want to be able to send rich text, but im hitting a wall here. what i want to do is send the font name, style, and color before every text so that way it will format it on the other end and display it in another richtextbox. right now im trying to send the .rtf property but i cant add it to the richtextbox...it just wont show anything and wont...
0
1038
by: Pramod | last post by:
Hi all, I have created a text editor using the richtextbox in c# on Japanese XP Here i have a comboBox to Select the Font and apply it to the selected text. When i select some text and set the font as MS Gothic or some other such as Times New Roman the font is set to the whole text of the Richtextbox, sometimes it goes to Microsoft san serif by default i am not able to set the font properly
0
1157
by: Pramod | last post by:
Hi all, I have created a text editor using the richtextbox in c# on Japanese XP Here i have a comboBox to Select the Font and apply it to the selected text. When i select some text and set the font as MS Gothic or some other such as Times New Roman the font is set to the whole text of the Richtextbox, sometimes it goes to Microsoft san serif by default i am not able to set the font properly
6
7143
by: andreas | last post by:
A selected text has fontstyles like bold and italic and underscore I want to remove one of them without changing the other fontstyles. How to do that? Thanks for any response
0
2061
by: Vimalathithan | last post by:
I just developing a editor. I have provide the options like Bold, Italic, underlin, font change, font size change. These font options are keep in with one toolstripbutton. the toolstripbar keep inside with panel. The RichTextBox keep inside with other panel. The panel height and width is same with RichTextBox. The RichTextBox both scrolling options are make it as false. I done the coding for RichTextBox's height to fit with...
9
3015
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
I want to open a text file and format it into a specific line and then apply color to a specific location of the text and then display it in a RichTextBox after all of this is done. I can do all of the above after the file is loaded into the RichTextBox, and I am trying to speed the process up by doing it in a temp file.
1
10155
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
9995
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...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
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
6776
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
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.