Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting (by bold, italic etc.) only part of a string 1

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
535
0
16
MU
Hi Team!

Is there an idea to show only part of a string with highlight (say by making that part Bold or Italic)
For example, suppose I have a text box and a label control. The label is 'Tek-Tips forum is Amazing'.

If I type, 'Tips' in text box, the label should show
Tek-Tips forum is Amazing

If I type 'Ama' in the text box, the label should show
Tek-Tips forum is Amazing

etc...

Can anyone share any lead to an idea?

Thanks,
Rajesh
 
Sorry, Rajesh, but this is impossible with native VFP controls. It's something that I have always wished for. The only way to do it natively in VFP is to break the string up into separate sub-strings, which is not always feasible.

You can do it by using the Microsft Rich Text control that comes with VFP. Or by adding a web browser control to your form and then formatting the text as HTML. Both of those approaches are quite complicated, but they might be worth investigating.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi dear Mike... Thanks...

Yes, I knew there is no straight method in VFP.
Whatever way it is, if that can be achieved (to have in a VFP application), it would be great!
If I come across something, it will be here for sure!

Anyone else, any thoughts please.

Rajesh
 
As Mike Lewis suggests we use a webbrowser on a form. It takes a bit of work but possible.

Screenshot_-_7_30_2022_6_36_26_AM_xoucar.png




If you want to get the best response to a question, please check out FAQ184-2483 first.
 
BTW, I believe the same problem exists in reports. I had to break up the text line into sections. Don't know any other easy way.

Steve
 
As I mentioned earlier, the rich-text control and the web browser control are both good possibilities. But perhaps they are more suited for displaying large chunks of text rather than small snippets. If the requirement is to apply different styles within a label, I would have my doubts. But it's always worth a try.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I have a feeling the OP wants an incremental search textbox highlighting the portion of text that was typed, after re-reading the question.



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi all,

Sorry for that silence from my side.

Mike Gagnon, yes, I need this for something like that, but not limited to incremental search.

Thanks
 
Rajesh

You cannot do this with any of the VFP controls, nor any activex that I can think of.



If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Given your original post, how would you expect

Tek-Tips forum is Amazing. Tek-Tips is wonderful.

to be displayed if you typed 'Tips' in text box?
 
Rajesh,

While you cannot change the style of just part of a string, I wonder if there is a different way of achieving your goal.

Presumably, you want to highlight part of the string in some way, to draw the user's attention to it. You can't do that with any of the "font" properties, such as FontBold, FontItalic, FontSize, etc. Nor with ForeColor or BackColor.

One option might be to underline the relevant substring. But not by using FontUnderline. Instead, actually place a Line control below the text. You would have to calculate its exact width and its Left property, according to the position of the sub-string within the string. It would be much easier to do that if the label was formatted with a fixed-width font such as Courier New. Make the line quite thick, and format it in a distinctive colour such as red.

But I'm guessing it would not look particularly nice, and might not achieve the desired effect.

Another, similar, approach would be to create a Shape object. Give it a thick, red border and set its BackStyle to Transparent. Then position it over and in front of the bit of text that you want to highlight.

I accept that these suggestions might not work. I just wanted to make the point that it is always worth trying to find a different approach to achieving your ultimate goal.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Dear Gagnon,
Yes, I feel that too. But, let's dream of achieving something similar, ins't it?

Dear Mike,
Yes, let me keep this goal in mind and try other road to reach my destination, :)

Thanks,
Rajesh

 
Rajesh,

we need to know more about what you are trying to achieve. As has been said you can't have mixed fonts within labels, textboxes or other native VFP controls.

But if this is some sort of lookup would this approach work?

Screenshot_2022-08-02_140116_bhyw9f.png


this is done using the grid column's dynamicbackcolor property. Having displayed a grid of useful data... the user can type into that textbox top right.... once they have typed more than 3 chars the .interactivechange event calls the grid's refresh and the dynamicbackcolor gets re-evaluated. if the underlying 'controlsource' contains that string.... highlight. it highlights the entire column rather than just that string but perhaps that's good enough?

hth

n
 
Dear Nigel,
Thank you.
Yes, this is a good idea indeed, somewhat similar to what I need.

I have to show a help list, say, in a grid or a list box from a table/cursor field. When user types into a textbox, the list will be filtered for those records with the string from user appearing anywhere in it, case-insensitive. The highlighting I require, is to show where the string is appearing in the field content and hence that record was included in the list. Basically we can think of this is something similar to the Contacts search in Android phones.

Thanks,
Rajesh
 
Rajesh,

then you are probably already showing a grid of filtered records...... highlighting the column should be good enough?

i do similar for browsing records..

Screenshot_2022-08-02_154227_gsyosa.png


in this case the filter reduces the record set and i've not been tempted to highlight....



hth

n
 
Hi Nigel,

Yes, that's only in fact what is required.
I was just thinking of making it a bit more informative!

Thanks
Rajesh
 
Dear all,

Now I prepared a simple incremental search with a textbox and a grid.
It still doesn't have the Highlighting feature that we are discussing, but it serves the purpose.

Thank you all for your time
Rajesh

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top