Solved

How to change selection backcolor in a RichTextBox

Posted on 2002-06-28
6
1,157 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

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 document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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