RichViewActions ( http://www.trichview.com/resources/actions/ ) implements something like this. But not exactly like in MS Word (In MS Word, this is a combo button, displaying the last applying color, and it allows to reapply the last color on single click; this is not impemented yet)
Thank you, but I mean, how to get all the fontstyle for the cursor position in the text, the fontstyle is not limited to color, but all the style like color, fontname, font size etc.
When I get the style and saved it to an object like fs:Tfontstyle, then I can apply this fs to any text selected and change the text selection style exactly like the fontstyle I want.
You can do it using ApplyStyleConversion method.
This method calls OnStyleConversion event for all text item in the selection, allowing to change font style properties.
var StyleNo: Integer;
if TextStyle<>nil then begin
StyleNo := RVStyle1.TextStyles.FindSuchStyle(0, RVAllFontInfoProperties);
if StyleNo<0 then begin
RVStyle1.TextStyles.Add;
StyleNo := RVStyle1.TextStyles.Count-1;
RVStyle1.TextStyles[StyleNo].Assign(TextStyle);
RVStyle1.TextStyles[StyleNo].Standard := False;
end;
RichViewEdit1.ApplyTextStyle(StyleNo);
end;
if StyleNo>=0 then
RichViewEdit1.ApplyTextStyle(StyleNo);
The only problem with this solution is: the stored value of StyleNo becomes invalid after creating a new document (File | New) or loading another document (File | Open), so you should reset it to -1.