hidrau
asked on
Changing the highlight color of selection text
Hello guys
I am developing a system that can use microsoft sapi, I have a richedit with a text and my application will read it word by word, when my text is being read, I highlight the word that is being read, but the default colour or highlight comes from windows control and it is blue and color font white, I would like to change the color of my highlight and the font to a yellow hightligh and black color font.
How could I do that?
Thanks
I am developing a system that can use microsoft sapi, I have a richedit with a text and my application will read it word by word, when my text is being read, I highlight the word that is being read, but the default colour or highlight comes from windows control and it is blue and color font white, I would like to change the color of my highlight and the font to a yellow hightligh and black color font.
How could I do that?
Thanks
also according to this http://groups.google.com/group/borland.public.delphi.winapi/browse_thread/thread/6e26aa50c565965/bf36cbaedf5dc137%23bf36cbaedf5dc137
it seems that indeed it cannot be done whitout modifying the system wide settings
it seems that indeed it cannot be done whitout modifying the system wide settings
well .. I got your results by using:
RichEdit1.SelAttributes.Co lor:=clwhi te;
and setting the
RichEdit1.Color:=clblue;
from designer
pretty ugly solution :)
RichEdit1.SelAttributes.Co
and setting the
RichEdit1.Color:=clblue;
from designer
pretty ugly solution :)
ASKER
Ciuly, I think I need your help here, I don't know how could I highlight each word that is being read as you suggested, after reading the word, it must come back to the original color, could you lend me a hand here? This is the code that I am using .
Thanks
// Get the event from the event queue
tEvent := ChantTTS1.GetChantTTSEvent (0);
// Check to see if there is text in the text box
If Length(Texto) > 1 then
begin
wordLength := 0;
// Get the current word spoken using word position
startPosition := tEvent.Position;
Memo1.SetFocus;
Memo1.SelStart := startPosition;
// Get the EngineAPI to determine is SAPI4 or SAPI5
engineAPI := ChantTTS1.GetNumberPropert y(CNPEngin eAPI);
if engineAPI = CESAPI5TTS then wordLength := tEvent.Length+1; // Get the word length
if engineAPI = CESAPI4TTS then
begin
// SAPI4 doesn't provide ength so calculate it
str := Copy(Texto,startPosition+1 ,Length(Te xto));
If Pos(' ',str) = 0 Then endOfWord := Length(Str)
Else endOfWord := Pos(' ',str);
if (endOfWord > 0) then wordLength := Length( Copy(texto,startPosition,e ndOfWord)) //endOfWor d
else wordLength := Length(texto) - startPosition;
end;
Memo1.SelLength := wordLength-1;
End;
// Remove the event from the event queue
ChantTTS1.RemoveResource(C SREvent, 0);
Thanks
// Get the event from the event queue
tEvent := ChantTTS1.GetChantTTSEvent
// Check to see if there is text in the text box
If Length(Texto) > 1 then
begin
wordLength := 0;
// Get the current word spoken using word position
startPosition := tEvent.Position;
Memo1.SetFocus;
Memo1.SelStart := startPosition;
// Get the EngineAPI to determine is SAPI4 or SAPI5
engineAPI := ChantTTS1.GetNumberPropert
if engineAPI = CESAPI5TTS then wordLength := tEvent.Length+1; // Get the word length
if engineAPI = CESAPI4TTS then
begin
// SAPI4 doesn't provide ength so calculate it
str := Copy(Texto,startPosition+1
If Pos(' ',str) = 0 Then endOfWord := Length(Str)
Else endOfWord := Pos(' ',str);
if (endOfWord > 0) then wordLength := Length( Copy(texto,startPosition,e
else wordLength := Length(texto) - startPosition;
end;
Memo1.SelLength := wordLength-1;
End;
// Remove the event from the event queue
ChantTTS1.RemoveResource(C
you said in your question that this is with trichedit. in your code I see Memo1 whichi tells me it's about TMemo. So which one is it?
if it's a memo, you cannot do anything with the selection text color. only in richedit you can do that.
if it's a memo, you cannot do anything with the selection text color. only in richedit you can do that.
ASKER
no, only the name is a memo the component is a richedit
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, it changes my color font and for change the background color of my selection, is it possible?
no. only if chaning the system wide settings.
you will have to choose an appropriate font color so that the selection will be visible on blue background.
you can of course make the font be bold. that will make it more visible. the way to do it is similar to the color changing (you will need to also have a variable to save the initial style in. the change will be done like:
Memo1.SelAttributes.Style := Memo1.SelAttributes.Style + [fsBold];
if you consider, you can also change the font size to be bigger. or the font face itself displaying in some other font face.
you will have to choose an appropriate font color so that the selection will be visible on blue background.
you can of course make the font be bold. that will make it more visible. the way to do it is similar to the color changing (you will need to also have a variable to save the initial style in. the change will be done like:
Memo1.SelAttributes.Style := Memo1.SelAttributes.Style + [fsBold];
if you consider, you can also change the font size to be bigger. or the font face itself displaying in some other font face.
ASKER
yeah ciuly, thanks very much for you support, it worked very fine.
regarding changing the background I was able to work around with RxrichEdit that I have installed in delphi. I had forgot it.
Thanks
regarding changing the background I was able to work around with RxrichEdit that I have installed in delphi. I had forgot it.
Thanks
ASKER
Ciuly, I made what you asked me to try, bellow you have the the code. Something that is happening is that I am having a lot of tremble on screen, I suspect that this is because this line Memo1.SelStart := 0;
Could you check where I could improbe this code to avoid the tremble?
Thanks
// Get the event from the event queue
tEvent := ChantTTS1.GetChantTTSEvent (0);
// Check to see if there is text in the text box
If Length(Texto) > 1 then
begin
wordLength := 0;
// Get the current word spoken using word position
startPosition := tEvent.Position;
Memo1.SetFocus;
Memo1.SelStart := 0;
Memo1.SelLength := length(Texto);
Memo1.SelAttributes.Color := clBlack;
Memo1.SelAttributes.BackCo lor := clwhite;
Memo1.SelLength := 0;
Memo1.SelStart := startPosition;
// Get the EngineAPI to determine is SAPI4 or SAPI5
engineAPI := ChantTTS1.GetNumberPropert y(CNPEngin eAPI);
if engineAPI = CESAPI5TTS then wordLength := tEvent.Length+1; // Get the word length
if engineAPI = CESAPI4TTS then
begin
// SAPI4 doesn't provide ength so calculate it
str := Copy(Texto,startPosition+1 ,Length(Te xto));
If Pos(' ',str) = 0 Then endOfWord := Length(Str)
Else endOfWord := Pos(' ',str);
if (endOfWord > 0) then wordLength := Length( Copy(texto,startPosition,e ndOfWord)) //endOfWor d
else wordLength := Length(texto) - startPosition;
end;
Memo1.SelLength := wordLength-1;
Memo1.SelAttributes.Color := clblack;
Memo1.SelAttributes.BackCo lor := clYellow;
Memo1.SelLength := 0;
End;
// Remove the event from the event queue
ChantTTS1.RemoveResource(C SREvent, 0);
Could you check where I could improbe this code to avoid the tremble?
Thanks
// Get the event from the event queue
tEvent := ChantTTS1.GetChantTTSEvent
// Check to see if there is text in the text box
If Length(Texto) > 1 then
begin
wordLength := 0;
// Get the current word spoken using word position
startPosition := tEvent.Position;
Memo1.SetFocus;
Memo1.SelStart := 0;
Memo1.SelLength := length(Texto);
Memo1.SelAttributes.Color := clBlack;
Memo1.SelAttributes.BackCo
Memo1.SelLength := 0;
Memo1.SelStart := startPosition;
// Get the EngineAPI to determine is SAPI4 or SAPI5
engineAPI := ChantTTS1.GetNumberPropert
if engineAPI = CESAPI5TTS then wordLength := tEvent.Length+1; // Get the word length
if engineAPI = CESAPI4TTS then
begin
// SAPI4 doesn't provide ength so calculate it
str := Copy(Texto,startPosition+1
If Pos(' ',str) = 0 Then endOfWord := Length(Str)
Else endOfWord := Pos(' ',str);
if (endOfWord > 0) then wordLength := Length( Copy(texto,startPosition,e
else wordLength := Length(texto) - startPosition;
end;
Memo1.SelLength := wordLength-1;
Memo1.SelAttributes.Color := clblack;
Memo1.SelAttributes.BackCo
Memo1.SelLength := 0;
End;
// Remove the event from the event queue
ChantTTS1.RemoveResource(C
from what I see, you never set memo1.selstart to a strict pozitive value. why is that? as I see there, you will alway select the text from the start to the current word. is that what you want to do?
ASKER
I wasn't able to do something different,
After highlighting the word I wasn't able to come back the default, the way I found was to select all the text once again and come back the default values.
maybe it is missing something or I am not knowing how to work with it better.
Could you lend me a hand?
After highlighting the word I wasn't able to come back the default, the way I found was to select all the text once again and come back the default values.
maybe it is missing something or I am not knowing how to work with it better.
Could you lend me a hand?
oh, well you didn't read my comments correctly. I said that you need some variables in which to hold the initial values of the properties you will change.
look at the accepted answer. you see me mentioning a restore:boolean and a savedcolor:TColor;
so you will also need to save the selstart property and restore it just as with the savedcolor variable.
you don't have to save the selstart though since that is not important (it will always be 0 or the length of the current word) but selstart needs to be saved in order to correctly restore the savedcolor ;)
sorry for not mentioning that before
look at the accepted answer. you see me mentioning a restore:boolean and a savedcolor:TColor;
so you will also need to save the selstart property and restore it just as with the savedcolor variable.
you don't have to save the selstart though since that is not important (it will always be 0 or the length of the current word) but selstart needs to be saved in order to correctly restore the savedcolor ;)
sorry for not mentioning that before
ASKER
ok, I will try and let you know
anyway I found this:
http://groups.google.ro/group/borland.public.delphi.winapi/browse_thread/thread/aadf1893ade484d/f125b1e3d3532b73%23f125b1e3d3532b73
tried this:
RichEdit1.SelStart:=2;
RichEdit1.SelLength:=3;
RichEdit1.SelAttributes.Co
and it returned yellow color on black background.
normally, the background will be dictated by the os, but it depends on the richedit background.
if you can get the richedit background to be blue and the font color to be white, then the highlight should be the one you want.
the issue is getting the background to be blue. I'll investigate further.