|
TCustomRichViewEdit.OnStyleConversion |
Top Previous Next |
|
Occurs while executing ApplyStyleConversion method. type TRVStyleConversionEvent = procedure (Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer) of object;
property OnStyleConversion:TRVStyleConversionEvent; This event allows you to create custom conversion procedure of text styles for the selected text. This event is called for all selected text items allowing to change their text style. It can be useful to implement commands like "make bold", "apply font", "change text color", etc. Parameters: StyleNo – current text style (index in the collection of styles, Style.TextStyles); UserData – value passed as a parameter in ApplyStyleConversion; AppliedToText – True, if this event was called for conversion of style of text item; False, if it was called for conversion of the current text style (CurTextStyleNo); NewStyleNo – initially equals to StyleNo; assign a new value to this parameter to change text style.
Example 1 procedure TMyForm.MyRichViewEditStyleConversion(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer); begin if not (AppliedToText and (rvprStyleProtect in Style.TextStyles[StyleNo].Protection)) then NewStyleNo := UserData; end; This example does exactly the same work as ApplyTextStyle, i.e. MyRichViewEdit.ApplyStyleConversion(StyleNo) will be equivalent to MyRichViewEdit.ApplyTextStyle(StyleNo). You can see that ApplyStyleConversion ignores protection of styles. If you wish to protect them, you should check protection yourself and do not change this style (like in the example above).
Example 2 procedure TMyForm.MyRichViewEditStyleConversion(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer); var FontInfo: TFontInfo; begin // creating text style with the desired attributes FontInfo := TFontInfo.Create(nil); try FontInfo.Assign(RVStyle1.TextStyles[StyleNo]); case UserData of TEXT_BOLD: if btnBold.Down then FontInfo.Style := FontInfo.Style+[fsBold] else FontInfo.Style := FontInfo.Style-[fsBold]; TEXT_ITALIC: if btnItalic.Down then FontInfo.Style := FontInfo.Style+[fsItalic] else FontInfo.Style := FontInfo.Style-[fsItalic]; TEXT_UNDERLINE: if btnUnderline.Down then FontInfo.Style := FontInfo.Style+[fsUnderline] else FontInfo.Style := FontInfo.Style-[fsUnderline]; TEXT_APPLYFONTNAME: FontInfo.FontName := FontName; TEXT_APPLYFONTSIZE: FontInfo.Size := FontSize; TEXT_APPLYFONT: FontInfo.Assign(FontDialog1.Font); TEXT_COLOR: FontInfo.Color := ColorDialog1.Color; TEXT_BACKCOLOR: FontInfo.BackColor := ColorDialog1.Color; // add your code here.... end; // if such text style already exists, reusing it NewStyleNo := RVStyle1.TextStyles.FindSuchStyle(StyleNo,FontInfo,RVAllFontInfoProperties); if NewStyleNo<0 then begin // if not, adding it RVStyle1.TextStyles.Add; NewStyleNo := RVStyle1.TextStyles.Count-1; RVStyle1.TextStyles[NewStyleNo].Assign(FontInfo); RVStyle1.TextStyles[NewStyleNo].Standard := False; end; finally FontInfo.Free; end; end; This example shows how to implement the following commands:
In this code:
See demos:
See also: See also methods: |