Solved

How to change selection backcolor in a RichTextBox

Posted on 2002-06-28
6
1,137 Views
Last Modified: 2007-12-19
Is there a way to change the background color of selected text in a RichTextBox? There is the SelectionColor property, but it's the forecolor. The BackColor property changes the whole control.

I want something like the "Highlight text" feature of Microsoft Word, for VB.NET please.

Thanks.
0
Comment
Question by:ricardog2
  • 3
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
CJ_S earned 100 total points
ID: 7118264
You will need to work with selectedrtf

RichTextBox1.SelectedRtf = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}{\colortbl ;\red255\green0\blue0;\red255\green0\blue255;}\uc1\pard\cf1\highlight2\f0\fs24 Mytext}"

It's pretty hard to get a grasp on though, but it will work once you get to know it well. i might have time available to do this automatically, but it'll take some time (and I'm leaving now)

CJ
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7118265
Easiest is to make it in Word -> copy to rtf field -> select that part -> msgbox(richtextbox.selectertf)

then copy the rtf code and use it to your likings.

CJ
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7119014
If you find no direct solution looking at the RTF codes generated by Word, take a look at this ocx with full source that implements this functionality via the rich edit library:

http://www.vbaccelerator.com/codelib/richedit/richedit.htm
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:ricardog2
ID: 7119371
The first solution seems to be more flexible, because that custom control needs a lot of dependency files and it's written in VB6. The VB.NET RichTextBox class has everything I need except the selection backcolor.

I'll look at the RTF Specification to understand that RTF code better.

Thank you for your replies.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7120059
I'm not sure how the .NET RichTextBox has been altered, but if it still is a wrapper around the riched*.dll then it may not support the RTF codes that specify selection backcolor.  That was an issue on several items, for me, when working with the VB6 richtextbox.  Things that were valid RTF codes, were not supported in the component (e.g., header/footer, page breaks, etc.)
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7120172
Azra,
Good to know!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now