Главная страница | назад





Article #17110: Changing RichEdit Font styles with HotKey combinations

 Question and Answer Database
FAQ2110D.txt Changing RichEdit Font styles with HotKey combinations
Category :VCL
Platform :All
Product :All 32 bit
Question:
How can I change the RichEdit font style in response to a
dedicated keystroke combination?
Answer:
The following example demonstrates changing the font style in a
TRichEdit component the following key combinations are pressed:
Ctrl + B — Turns on and off Bold styling
Ctrl + I — Turns on and off Italic styling
Ctrl + S — Turns on and off Strikeout styling
Ctrl + U — Turns on and off Underline styling
Note: It is possible to set the font to include multiple styles.
Example:
const
KEY_CTRL_B = 02;
KEY_CTRL_I = 9;
KEY_CTRL_S = 19;
KEY_CTRL_U = 21;
procedure TForm1.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
case Ord(Key) of
KEY_CTRL_B: begin
Key := #0;
if fsBold in (Sender as TRichEdit).SelAttributes.Style then
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style — [fsBold] else
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style + [fsBold];
end;
KEY_CTRL_I: begin
Key := #0;
if fsItalic in
(Sender as TRichEdit).SelAttributes.Style then
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style — [fsItalic]
else
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style + [fsItalic];
end;
KEY_CTRL_S: begin
Key := #0;
if fsStrikeout in
(Sender as TRichEdit).SelAttributes.Style then
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style — [fsStrikeout]
else
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style + [fsStrikeout];
end;
KEY_CTRL_U: begin
Key := #0;
if fsUnderline in
(Sender as TRichEdit).SelAttributes.Style then
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style — [fsUnderline]
else
(Sender as TRichEdit).SelAttributes.Style :=
(Sender as TRichEdit).SelAttributes.Style + [fsUnderline];
end;
end;
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99