?
Solved

How to change selection backcolor in a RichTextBox

Posted on 2002-06-28
6
Medium Priority
?
1,185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 22

Accepted Solution

by:
CJ_S earned 400 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

765 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