Solved

Richtextbox - Need to capture color of text character

Posted on 2006-11-07
10
504 Views
Last Modified: 2010-04-23
I am converting a vb6 program to vb.net and am having a problem with the richtextbox control contained in the program.

In vb6, the user can enter text into a richtextbox and then highlight different characters.  During a pricing routine, this allows the calculation to distinguish between two different "types" of characters.

In vb6, this was the code:

      txtCopy.SelStart = Y - 1
      txtCopy.SelLength = 1
      If txtCopy.SelColor = RGB(255, 0, 0) Then...

In vb.net, I changed selstart to selectionstart and sellength to selectionlength.  I cannot find any replacement for selcolor that works with trying to capture the color of a character.
0
Comment
Question by:don2347
[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
  • 5
  • 3
  • 2
10 Comments
 
LVL 7

Expert Comment

by:rvidal393
ID: 17891897
Hi don2347,

txtCopy.SelectionColor did not work for you??

Cheers!
0
 

Author Comment

by:don2347
ID: 17891920
The code "If txtCopy.SelectionColor = color.red..." produces this error"operator '=' is not defined for types 'System.Drawing Color' and 'System.Drawing Color'."

It appears the txt.selectioncolor is used to set the color, but not read the color property.
0
 
LVL 7

Expert Comment

by:rvidal393
ID: 17892010
don2347,

That's strange.  What version are you using.  It works fine in VB 2005
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:don2347
ID: 17892079
vb.net 2003, version 7.1.3088
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17892163
Hi don2347;

Try it this way

        txtCopy.SelectionStart = Y - 1
        txtCopy.SelectionLength = 1
        If txtCopy.SelectionColor = Color.Red Then
            MessageBox.Show("Red")
        Else
            MessageBox.Show("NOT Red")
        End If


Fernando
0
 

Author Comment

by:don2347
ID: 17892186
Thanks.  I add that code and get the compile error:

C:\vb.net\Hotels\Hotels\Menu.vb(4020): Operator '=' is not defined for types 'System.Drawing.Color' and 'System.Drawing.Color'.
0
 

Author Comment

by:don2347
ID: 17892194
I should mention that the error is on the code:
txtCopy.SelectionColor = Color.Red
0
 
LVL 7

Accepted Solution

by:
rvidal393 earned 125 total points
ID: 17892219
rvidal393,
One more thing to try:

if txtCopy.SelectionColor.equals(color.red) then
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 17892342
Hi don2347;

It always helps to know what version of Visual Studio you are working in.

This Code will work for VB .Net 2003

        txtCopy.SelectionStart = Y - 1
        txtCopy.SelectionLength = 1

        If txtCopy.SelectionColor.Equals(Color.Red) Then
            MessageBox.Show("Red")
        Else
            MessageBox.Show("NOT Red")
        End If

This Code will work for VB .Net 2005 Only

        txtCopy.SelectionStart = Y - 1
        txtCopy.SelectionLength = 1
        If txtCopy.SelectionColor = Color.Red Then
            MessageBox.Show("Red")
        Else
            MessageBox.Show("NOT Red")
        End If


Fernando
0
 

Author Comment

by:don2347
ID: 17892685
I meant to split the points - sorry Fernando.  Thank you for your help.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb.net threads keep increasing 2 48
Get month and date in a format 4 44
VB/ASP.Net "Value of type 'Date' cannot be converted to 'Integer'" 12 42
Need help with another query 10 35
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

735 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