|
TCustomRichViewEdit.OnParaStyleConversion |
Top Previous Next |
|
Occurs while executing ApplyParaStyleConversion method. type TRVStyleConversionEvent = procedure (Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer) of object;
property OnParaStyleConversion:TRVStyleConversionEvent; (introduced in version 1.7) This event allows you to create custom conversion procedure for styles of the selected paragraphs. This event is called for all selected items allowing to change their paragraph style. It can be useful for implementing commands like "change paragraph alignment", "change paragraph indents", etc. Parameters: StyleNo – current paragraph style (index in collection of styles, Style.ParaStyles); UserData – value passed as a parameter in ApplyParaStyleConversion; AppliedToText – not used NewStyleNo – initially equals to StyleNo; assign a new value to this parameter to change paragraph style.
Example: procedure TMyForm.MyRichViewEditParaStyleConversion(Sender: TCustomRichViewEdit; StyleNo, UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer); var ParaInfo: TParaInfo; begin // creating paragraph style with the desired attributes ParaInfo := TParaInfo.Create(nil); try ParaInfo.Assign(RVStyle1.ParaStyles[StyleNo]); case UserData of PARA_ALIGNMENT: ParaInfo.Alignment := GetAlignment; PARA_INDENTINC: begin ParaInfo.LeftIndent := ParaInfo.LeftIndent+20; if ParaInfo.LeftIndent>1000 then ParaInfo.LeftIndent := 1000; end; PARA_INDENTDEC: begin ParaInfo.LeftIndent := ParaInfo.LeftIndent-20; if ParaInfo.LeftIndent<0 then ParaInfo.LeftIndent := 0; end; PARA_COLOR: ParaInfo.Background.Color := ColorDialog1.Color; // add your code here.... end; // if such paragraph style already exists, reusing it NewStyleNo := RVStyle1.ParaStyles.FindSuchStyle(StyleNo,ParaInfo,RVAllParaInfoProperties); if NewStyleNo<0 then begin // if not, adding it RVStyle1.ParaStyles.Add; NewStyleNo := RVStyle1.ParaStyles.Count-1; RVStyle1.ParaStyles[NewStyleNo].Assign(ParaInfo); RVStyle1.ParaStyles[NewStyleNo].Standard := False; end; finally ParaInfo.Free; end; end; This example shows how to implement the following commands:
In this code:
You can see that for new paragraph styles added in this event, Standard property is set to False. It is important, otherwise DeleteUnusedStyles will not be able to delete this style, even if all paragraphs of this style will be removed.
See demos:
See also: See also methods: |