473,782 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to set text color in RichTextBox

hi,
i'm trying to use the RichTextBoxSele ctionColor property, but in any
combination of command order i try, the text color is not changed. the
only time it worked was when i set SelectionStart = 0.

here's one version i tried:

String res = "Failed";
int selectionStart = rtbTestResult.T extLength;
rtbTestResult.A ppendText(res + Environment.New Line);
// OR rtbTestResult.T ext += res + Environment.New Line;
rtbTestResult.S electionStart = selectionStart;
rtbTestResult.S electionLength = res.Length;
rtbTestResult.S electionColor = Color.Red;

any ideas?

Sep 4 '06 #1
4 3152
Hi,

I am unable to verify your problem. Your code works as expected. The
word Failed is appended to whatever text is present, and the word is
indeed colored red.

If you open a new project, using only the RichTextBox, do you still get no
color?
On Mon, 04 Sep 2006 11:54:00 +0200, <ts********@gma il.comwrote:
hi,
i'm trying to use the RichTextBoxSele ctionColor property, but in any
combination of command order i try, the text color is not changed. the
only time it worked was when i set SelectionStart = 0.

here's one version i tried:

String res = "Failed";
int selectionStart = rtbTestResult.T extLength;
rtbTestResult.A ppendText(res + Environment.New Line);
// OR rtbTestResult.T ext += res + Environment.New Line;
rtbTestResult.S electionStart = selectionStart;
rtbTestResult.S electionLength = res.Length;
rtbTestResult.S electionColor = Color.Red;

any ideas?


--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 4 '06 #2
Morten Wennevik wrote:
Hi,

I am unable to verify your problem. Your code works as expected. The
word Failed is appended to whatever text is present, and the word is
indeed colored red.
i get it in black. can it be related to the fact that subsequent calls
to this method add more text to the richtextbox, in another case block?
(the code above is in a case block of a switch statement).
If you open a new project, using only the RichTextBox, do you still get no
color?

i tried to make a simple app, where i preloaded the textbox with lorem
ipsum, and on a button click event i did SelectionColor = Color.Red,
and indeed any text i selected with the mouse was painted red. in this
case, however, rtbTestResults. ReadOnly = true.

while writing this post i tried to set HideSelection = false, and
"Failed" blinked in red for a moment, but when more text was added, it
turned black again.

tsahi
On Mon, 04 Sep 2006 11:54:00 +0200, <ts********@gma il.comwrote:
hi,
i'm trying to use the RichTextBoxSele ctionColor property, but in any
combination of command order i try, the text color is not changed. the
only time it worked was when i set SelectionStart = 0.

here's one version i tried:

String res = "Failed";
int selectionStart = rtbTestResult.T extLength;
rtbTestResult.A ppendText(res + Environment.New Line);
// OR rtbTestResult.T ext += res + Environment.New Line;
rtbTestResult.S electionStart = selectionStart;
rtbTestResult.S electionLength = res.Length;
rtbTestResult.S electionColor = Color.Red;

any ideas?

--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 4 '06 #3

ts********@gmai l.com wrote:
Morten Wennevik wrote:
Hi,

I am unable to verify your problem. Your code works as expected. The
word Failed is appended to whatever text is present, and the word is
indeed colored red.

i get it in black. can it be related to the fact that subsequent calls
to this method add more text to the richtextbox, in another case block?
(the code above is in a case block of a switch statement).
If you open a new project, using only the RichTextBox, do you still get no
color?
i tried to make a simple app, where i preloaded the textbox with lorem
ipsum, and on a button click event i did SelectionColor = Color.Red,
and indeed any text i selected with the mouse was painted red. in this
case, however, rtbTestResults. ReadOnly = true.

while writing this post i tried to set HideSelection = false, and
"Failed" blinked in red for a moment, but when more text was added, it
turned black again.

tsahi
On Mon, 04 Sep 2006 11:54:00 +0200, <ts********@gma il.comwrote:
hi,
i'm trying to use the RichTextBoxSele ctionColor property, but in any
combination of command order i try, the text color is not changed. the
only time it worked was when i set SelectionStart = 0.
>
here's one version i tried:
>
String res = "Failed";
int selectionStart = rtbTestResult.T extLength;
rtbTestResult.A ppendText(res + Environment.New Line);
// OR rtbTestResult.T ext += res + Environment.New Line;
rtbTestResult.S electionStart = selectionStart;
rtbTestResult.S electionLength = res.Length;
rtbTestResult.S electionColor = Color.Red;
>
any ideas?
>


--
Happy Coding!
Morten Wennevik [C# MVP]
i fixed it. i replaced all calls to Text += "some string" to
AppendText("som e string"), and it works. it must be something with this
+= operator.

Sep 4 '06 #4
I don't think using AppendText instead of += is the reason you got black
text. More likely you overwrote the red text with black at a later point.

Glad to see it works now, though.
On Mon, 04 Sep 2006 20:49:58 +0200, <ts********@gma il.comwrote:
>
ts********@gmai l.com wrote:
>Morten Wennevik wrote:
Hi,

I am unable to verify your problem. Your code works as expected. The
word Failed is appended to whatever text is present, and the word is
indeed colored red.

i get it in black. can it be related to the fact that subsequent calls
to this method add more text to the richtextbox, in another case block?
(the code above is in a case block of a switch statement).
If you open a new project, using only the RichTextBox, do you still
get no
color?

i tried to make a simple app, where i preloaded the textbox with lorem
ipsum, and on a button click event i did SelectionColor = Color.Red,
and indeed any text i selected with the mouse was painted red. in this
case, however, rtbTestResults. ReadOnly = true.

while writing this post i tried to set HideSelection = false, and
"Failed" blinked in red for a moment, but when more text was added, it
turned black again.

tsahi
On Mon, 04 Sep 2006 11:54:00 +0200, <ts********@gma il.comwrote:

hi,
i'm trying to use the RichTextBoxSele ctionColor property, but in any
combination of command order i try, the text color is not changed..
the
only time it worked was when i set SelectionStart = 0.

here's one version i tried:

String res = "Failed";
int selectionStart = rtbTestResult.T extLength;
rtbTestResult.A ppendText(res + Environment.New Line);
// OR rtbTestResult.T ext += res + Environment.New Line;
rtbTestResult.S electionStart = selectionStart;
rtbTestResult.S electionLength = res.Length;
rtbTestResult.S electionColor = Color.Red;

any ideas?


--
Happy Coding!
Morten Wennevik [C# MVP]

i fixed it. i replaced all calls to Text += "some string" to
AppendText("som e string"), and it works. it must be something with this
+= operator.


--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 5 '06 #5

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

Similar topics

2
17289
by: Hariharan S | last post by:
Hi Guys, I have a string, say "Hello World" and would like to format the way I want to (say, wanna have the Hello to be bold italic and the World to be of font size 14 or so) and put it in the RichTextBox, I created. Just want to paste or write this string to the RichTextBox; what command should I use? I used the following command and it did not help ... richTextBox.SelectionFont = <some font selected>
3
21164
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 text"; works) Thanks for your attention & solutions
2
4017
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 displayed, effictively scrolling to the last line of the text box all the time. Can anyone help as I cannot seem to find a way to do this. Thanks
1
2691
by: Carlos Lozano | last post by:
I need to merge the content of two richtextboxes. It can not be accomplished using the RichtTextBox.Text field because all format will be lost. So it has to be done using the RichtTextBox.Rtf field, but I loose part of it as follows: private void MergeRtf() { // having the RichTextBox controls.
1
5457
by: TheBinar | 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...
2
6071
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). How is this done? Also, how do I delete the current selection? Thanks.
6
20658
by: Al | last post by:
Hi Is there any what to convert content of a richTexBoxt from rtf to text? thanks Al
3
7190
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 just add plain (e.g.. rtf.Text += "new stuff..."; ) but some text, when added, I want to be in a different color or font size. Find() will not work because the text will vary. I have delimiters on it so I could recognize it with a regular ...
2
2589
by: drfreaky | last post by:
Hello, I want to use a richtextbox for logging status messages. I have three kind of message types and want to use different formatting for them. My problem is, I change the color, add the text and the added text is shown in another color. I scroll to the end and want to add the next status line using appendtext. But now the previous line lost its formatting...... I want to keep the formatting… Do you have a solution? BTW I am using...
9
3014
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.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10146
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8968
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
7494
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
6735
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
5378
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
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
3
2875
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.