Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 517
  • Last Modified:

Richtextbox - Need to capture color of text character

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
don2347
Asked:
don2347
  • 5
  • 3
  • 2
1 Solution
 
rvidal393Commented:
Hi don2347,

txtCopy.SelectionColor did not work for you??

Cheers!
0
 
don2347Author Commented:
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
 
rvidal393Commented:
don2347,

That's strange.  What version are you using.  It works fine in VB 2005
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
don2347Author Commented:
vb.net 2003, version 7.1.3088
0
 
Fernando SotoRetiredCommented:
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
 
don2347Author Commented:
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
 
don2347Author Commented:
I should mention that the error is on the code:
txtCopy.SelectionColor = Color.Red
0
 
rvidal393Commented:
rvidal393,
One more thing to try:

if txtCopy.SelectionColor.equals(color.red) then
0
 
Fernando SotoRetiredCommented:
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
 
don2347Author Commented:
I meant to split the points - sorry Fernando.  Thank you for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now