Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change color of a substring of a caption
Message
From
05/03/2019 08:42:45
 
 
To
05/03/2019 08:26:52
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01666960
Message ID:
01666987
Views:
58
>>>Hi,
>>>
>>>I have a window/form that has many check boxes. Each check box has a caption. I want to add a text box at the top of the form so that the user can search for any check box caption which contains the entered text. For example, when a user enters "fox", a method of the form will scan all check boxes and check if the caption has the word "fox." So far, it is all fairly easy to do.
>>>
>>>But then I want the substring of the caption to change the color (or make it bold). For example, if a check box has a caption
>>>"Visual FoxPro" I want the word/substring "Fox" to be highlighted by a color or make it bold.
>>>
>>>Is this possible? And if yes, how? TIA
>>
>>Since you can't set color (forecolor or backcolor) for individual characters in a control, this will be hard. You could do something by dynamically overlaying controls that are appropriately colored, but there'll be a lot of overhead when it runs (assuming you're applying this to a bunch of controls).
>>
>>I wonder whether simply doing something with SelStart and SelLength would accomplish your goals at a lower cost.
>>
>I also wonder at the overhead of single pixel massaging. Will be interesting to read/time implementations.
>As the question is ONLY about chkboxes and leaves ot option groups, my first try would be to build a complex control, a container housing a chkbox with no caption, a caption property on the container and 2n+1 labels building the line usually used as caption of chkbox.
>
>The start and width of each label would have to be calculated and the "usual" caption be split into an array of searchidentical and searchdifferent strings
>
>example : string search for "ox" in "Foxpro oxymorons"
>
>"F"
>"ox"
>"pro "
>"ox"
>"morons"
>
>build the "chkbox caption line" dynamically from 5 labels, even numbered labels with different backcolor.
>Might be easier and faster...

I would create a class that had normal checkbox but with no caption portion, and use a label instead which mimics the appearance of the text next to the checkbox.

For overlays, you'll need a second label, normally not visible, along with a third label to determine the width of the first part of the text which may exist before the found string.

Add a method to the class which highlights the indicated phrase, and another which clears the highlighting. The highlight method will look to see if the text exists in the label that's always visible next to the checkmark. If so, use one of the labels to populate with the leading text and set it to AutoSize = .t. so it gets the width, and then use the other lone to set it to the text found in the first label, and position it at the start of the always visible label, aligned with the top, and its left-side value set to the width of the one with the text at the left.

Tamar Granor's solution is better. Using a control and SelStart and SelLength with highlighted colors set to be more vivid than normal selected text ... it will display the solution fast and very nice I think.
Previous
Reply
Map
View

Click here to load this message in the networking platform