// global variables...
var TxtHrzBar,TxtVrtBar: integer;
SelFontFormat: TFontParams;
PageMemo: TRichMemo;
// List of mask-constants for changing attribute-types in SetRangeParams...
// tmm_Color - font color would be modified (fnt.Color field must be populated)
// tmm_Name - font name would be modified (fnt.Name field must be populated)
// tmm_Size - font size would be modified (fnt.Size field must be populated)
// tmm_Styles - font styles modified per AddFontStyle and RemoveFontStyle parameters
// (font styles: fsBold, fsItalic, fsUnderline, fsStrikeOut)
// tmm_BackColor - text highlight (background) color would be modified
// (fnt.HasBkClr and fnt.BkColor fields must be populated).
procedure TCmdForm.btnBoldClick(Sender: TObject);
begin
PageMemo.GetTextAttributes(PageMemo.SelStart, SelFontFormat);
TxtHrzBar:= GetScrollPos(PageMemo.handle,SB_HORZ);
TxtVrtBar:= GetScrollPos(PageMemo.handle,SB_VERT);
if PageMemo.SelLength=0
then begin
if (fsBold in SelFontFormat.Style = False)
then SelFontFormat.Style:=SelFontFormat.Style + [fsBold]
else SelFontFormat.Style:=SelFontFormat.Style - [fsBold];
PageMemo.SetTextAttributes(PageMemo.SelStart, PageMemo.SelLength, SelFontFormat);
end
else begin
if (fsBold in SelFontFormat.Style=False)
then begin
PageMemo.SetRangeParams(PageMemo.SelStart, // int: begin position of selection, 0 sets start of file.
PageMemo.SelLength, // int: length of selection set.
[tmm_Styles], // cst: modify types, [] sets to empty, or [tmm_Styles,tmm_Color]
'', // str: font name, '' sets to empty.
0, // int: font size, 0 sets to empty.
0, // int: color, 0 sets to empty.
[fsBold], // cst: adding styles, [] sets to empty, or [fsBold,fsItalic]
[] // cst: remove styles, [] sets to empty, or [fsBold,fsItalic]
);
end
else begin
PageMemo.SetRangeParams (PageMemo.SelStart, // int: begin position of selection, 0 sets start of file.
PageMemo.SelLength, // int: length of selection characters, -1 sets end of file.
[tmm_Styles], // cst: modify types, [] sets to empty, or [tmm_Styles,tmm_Color]
'', // str: font name, '' sets to empty.
0, // int: font size, 0 sets to empty.
0, // int: color, 0 sets to empty.
[], // cst: adding styles, [] sets to empty, or [fsBold,fsItalic]
[fsBold] // cst: remove styles, [] sets to empty, or [fsBold,fsItalic]
);
end;
end;
SendMessage(PageMemo.handle, WM_HSCROLL, MakeLong(SB_THUMBPOSITION, TxtHrzBar), 0);
SendMessage(PageMemo.handle, WM_VSCROLL, MakeLong(SB_THUMBPOSITION, TxtVrtBar), 0);
PageMemo.SetFocus;
end;