473,810 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net richtextbox selectionstart coloring

Hi all,

I am trying to change the color of text that the user sees when they
are editing a richtextbox. This is the code I am using in the
TextChanged method of RichTextBox control.

Dim position As Integer = rtb.SelectionSt art
rtb.Refresh()
rtb.SelectionSt art = position

rtb.SelectionLe ngth = 1
rtb.SelectionCo lor = Color.Red

This works starting with the 2nd character. The first character typed
is not red, but all typed characters after that are. Not sure why.
Any ideas ?

Thanks,
Mark

Aug 17 '06 #1
2 4567
That's because the event is fired only after the use typed the first
character (and for other types subsequently). Just call the TextChanged
event handler programmaticall y first (may be in the form load event).

By the way, the same result can be achieved just be setting the ForeColor fo
the RTB.

HTH.

<ma*****@yahoo. comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Hi all,

I am trying to change the color of text that the user sees when they
are editing a richtextbox. This is the code I am using in the
TextChanged method of RichTextBox control.

Dim position As Integer = rtb.SelectionSt art
rtb.Refresh()
rtb.SelectionSt art = position

rtb.SelectionLe ngth = 1
rtb.SelectionCo lor = Color.Red

This works starting with the 2nd character. The first character typed
is not red, but all typed characters after that are. Not sure why.
Any ideas ?

Thanks,
Mark

Aug 17 '06 #2
Thanks.
Siva M wrote:
That's because the event is fired only after the use typed the first
character (and for other types subsequently). Just call the TextChanged
event handler programmaticall y first (may be in the form load event).

By the way, the same result can be achieved just be setting the ForeColor fo
the RTB.

HTH.

<ma*****@yahoo. comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.com.. .
Hi all,

I am trying to change the color of text that the user sees when they
are editing a richtextbox. This is the code I am using in the
TextChanged method of RichTextBox control.

Dim position As Integer = rtb.SelectionSt art
rtb.Refresh()
rtb.SelectionSt art = position

rtb.SelectionLe ngth = 1
rtb.SelectionCo lor = Color.Red

This works starting with the 2nd character. The first character typed
is not red, but all typed characters after that are. Not sure why.
Any ideas ?

Thanks,
Mark
Aug 17 '06 #3

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

Similar topics

0
1391
by: nuwankkumara | last post by:
hai all, i am using RichTextBox as my editor , there i can't perform undo and redo when i have changed the color and font of the text as below: richBox.SelectionStart = index; richBox.SelectionLength = token.Length; richBox.SelectionColor = Color.Black; richBox.SelectionFont = regFont;
4
6233
by: DG | last post by:
i do: for(int i=0; i<10; i++) { txtLog.Text = i.ToString() + "\r\n" + txtLog.Text; startSelection = txtLog.SelectionStart; lenghtSelection = txtLog.SelectionLength; txtLog.Select(0, i.ToString().Length); if(i%2 == 0)
1
2249
by: Udi | last post by:
Hi, I need to update the last line of Lines in my derived RichTextBox. Since I can't do this: Lines = history as string; I need to copy 'Lines' to a tmp array, change it and copy it back to 'Lines': :
4
3154
by: tsahiasher | last post by:
hi, i'm trying to use the RichTextBoxSelectionColor 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.TextLength; rtbTestResult.AppendText(res + Environment.NewLine);
3
7192
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 ...
8
2624
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have created a Control that extends RichTextBox to do syntax-hilighting. My strategy is to have a timer that restarts every time a user types a key so that it can wait until the user pauses for at least 500 milliseconds, then perform its work. The hilighting simply goes through a list of keywords, finding each instance in the RichTextBox, and selecting it in order to change its color. I figured out how to remember where the cursor is and...
2
2107
by: aemihal | last post by:
Hello, I have a RichTextBox that has a large number of lines, well in excess of the amount that can be seen without scrolling. Upon an event, such as clicking a button, I would like to move the viewable portion of the RichTextBox to be able to see that particular line. In other words, if the RichTextBox has 1000 lines of text, how can I force the viewable portion to start at, say, line number 123? This is what I have tried so far: ...
1
1484
by: eBob.com | last post by:
After a lot of debugging effort I have to conclude that it does. Or at least can. I take a substring (RichTextBox.Text.Substring) before setting SelectionStart and after and get a different result. The second result begins two characters to the right of the first. In an earlier version of the program I did not have this problem. But in that version the RichTextBox actually appeared on a form. In the version of the program with the...
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
9603
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
10643
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...
0
10378
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...
1
10391
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,...
1
7664
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
6881
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
5550
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
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.