4 Replies - 1564 Views - Last Post: 18 January 2011 - 01:55 PM Rate Topic: -----

#1 kingfish23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-December 10

How do I make the selected text from a listbox the color blue?

Posted 17 January 2011 - 09:27 PM

This is in reguards to my previous question.
I have a multiline RichTextBox and a ListBox filled with keywords.
When I type in the letter t, or any other first letter of a keyword
I would like the ListBox to show, just like it does in VB
The response to my last question helped tremendously, but
How can I make my selection the color Blue?
Is This A Good Question/Topic? 0
  • +

Replies To: How do I make the selected text from a listbox the color blue?

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How do I make the selected text from a listbox the color blue?

Posted 18 January 2011 - 07:15 AM

You will need to select the text you just added, look into selectionstart and selectionlength of the richtextbox. Then use Select() to hilight the text that selectionstart and selectionlength determined for selection, then use RTB.SelectionColor = Color.Blue

This post has been edited by CharlieMay: 18 January 2011 - 07:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1057
  • View blog
  • Posts: 4,090
  • Joined: 02-July 08

Re: How do I make the selected text from a listbox the color blue?

Posted 18 January 2011 - 08:20 AM

If your looking to change the listbox items color then use the Owner Draw Listbox.
Was This Post Helpful? 0
  • +
  • -

#4 kingfish23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-December 10

Re: How do I make the selected text from a listbox the color blue?

Posted 18 January 2011 - 01:42 PM

View PostCharlieMay, on 18 January 2011 - 07:15 AM, said:

You will need to select the text you just added, look into selectionstart and selectionlength of the richtextbox. Then use Select() to hilight the text that selectionstart and selectionlength determined for selection, then use RTB.SelectionColor = Color.Blue

Thanks for the help, but I seem to get ALL of the text to change color and not just the keyword. I should know this using selectionstart and selectionlength but for some reason my mind seems "out there". I'm working on 3 different projects at the same time - almost, not a good idea I know. My listbox is VB Keywords in a txt file and I am attempting to create an editor that will color the Keywords Blue.
Thanks,
Steve

View Posthawkvalley1, on 18 January 2011 - 08:20 AM, said:

If your looking to change the listbox items color then use the Owner Draw Listbox.

That looks like a good listbox, but,
My listbox is VB Keywords loaded from a txt file and I am attempting to create an editor that will color the Keywords Blue in the multiline textbox.
Thanks,
Steve
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: How do I make the selected text from a listbox the color blue?

Posted 18 January 2011 - 01:55 PM

The easiest way would be to enter the text into the RTB as I assume you're doing from the selection. Then since you can get the length of that keyword you know the selection length, The selection start is the RTB.TextLength - the length of the keyword. You could also use Find to find the keyword starting at an index of the textlength - the rtb.textlength.

There is a topic here where someone was doing something similar. I'll add the link if I can find it but basically the other method would be to scan the RTB and colorize found words that match a list of the words in your list.

Here's the link I was talking about. There is a lot of what you're doing in it and it may help you with other areas.

This post has been edited by CharlieMay: 18 January 2011 - 02:23 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1