Как изменить стиль шрифта RichEdit нажатиями соответствующих комбинаций клавиш?

В примере стили шрифта меняются по нажатию след. комбинаций клавиш
        Ctrl + B - вкл/выкл жирного шрифта
        Ctrl + I - вкл/выкл наклонного шрифта
        Ctrl + S - вкл/выкл зачеркнутого шрифта
        Ctrl + U - вкл/выкл подчеркнутого шрифта


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;
 
« Предыдущая статья   Следующая статья »