RichForm.pas
资源名称:delphi.rar [点击查看]
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:12k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit RichForm;
- interface
- uses
- SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, ExtCtrls, Menus, ActnList, ToolWin, ImgList, ClipBrd,
- RichEdit, AppEvnts, ActnMan, ActnCtrls, ActnMenus, BandActn, CustomizeDlg;
- type
- TFormRichNote = class(TForm)
- FontDialog: TFontDialog;
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- ColorDialog: TColorDialog;
- ActionList: TActionList;
- acCentered: TAction;
- acUndo: TAction;
- acCut: TAction;
- acPaste: TAction;
- acCopy: TAction;
- acBold: TAction;
- acItalic: TAction;
- acRightAligned: TAction;
- acLeftAligned: TAction;
- acSave: TAction;
- acFont: TAction;
- acCountChars: TAction;
- Images: TImageList;
- SizeMenu: TPopupMenu;
- Small1: TMenuItem;
- Medium1: TMenuItem;
- Large1: TMenuItem;
- acHintColor: TAction;
- ControlBar: TControlBar;
- ComboFont: TComboBox;
- BarMenu: TPopupMenu;
- StatusBar: TStatusBar;
- acExit: TAction;
- ApplicationEvents1: TApplicationEvents;
- ColorBox1: TColorBox;
- Panel1: TPanel;
- ControlBarLower: TControlBar;
- RichEdit: TRichEdit;
- ActionToolBar1: TActionToolBar;
- ActionMainMenuBar1: TActionMainMenuBar;
- ActionManager1: TActionManager;
- CustomizeActionBars1: TCustomizeActionBars;
- ActionToolBar2: TActionToolBar;
- ActionToolBar3: TActionToolBar;
- procedure BoldExecute(Sender: TObject);
- procedure ItalicExecute(Sender: TObject);
- procedure ChangeAlignment(Sender: TObject);
- procedure AboutExecute(Sender: TObject);
- procedure ExitExecute(Sender: TObject);
- procedure OpenExecute(Sender: TObject);
- procedure SaveAsExecute(Sender: TObject);
- procedure BackColorExecute(Sender: TObject);
- procedure FontExecute(Sender: TObject);
- procedure CountCharsExecute(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure NewExecute(Sender: TObject);
- procedure SaveExecute(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure PrintExecute(Sender: TObject);
- procedure acSaveUpdate(Sender: TObject);
- procedure acBoldUpdate(Sender: TObject);
- procedure acItalicUpdate(Sender: TObject);
- procedure RichEditChange(Sender: TObject);
- procedure acCountcharsUpdate(Sender: TObject);
- procedure acCutExecute(Sender: TObject);
- procedure acCutUpdate(Sender: TObject);
- procedure acCopyExecute(Sender: TObject);
- procedure acPasteExecute(Sender: TObject);
- procedure acPasteUpdate(Sender: TObject);
- procedure acUndoExecute(Sender: TObject);
- procedure acUndoUpdate(Sender: TObject);
- procedure ActionListUpdate(Action: TBasicAction; var Handled: Boolean);
- procedure ToolButton17Click(Sender: TObject);
- procedure SetFontSize(Sender: TObject);
- procedure ComboFontClick(Sender: TObject);
- procedure RichEditSelectionChange(Sender: TObject);
- procedure acHintColorExecute(Sender: TObject);
- procedure BarMenuPopup(Sender: TObject);
- procedure ShowHint(Sender: TObject);
- procedure EndDock(Sender, Target: TObject; X, Y: Integer);
- procedure ControlBarLowerDockOver(Sender: TObject;
- Source: TDragDockObject; X, Y: Integer; State: TDragState;
- var Accept: Boolean);
- private
- FileName: string;
- Modified: Boolean;
- public
- function SaveChanges: Boolean;
- function Save: Boolean;
- function SaveAs: Boolean;
- procedure BarMenuClick (Sender: TObject);
- procedure CheckCapslock;
- end;
- var
- FormRichNote: TFormRichNote;
- implementation
- {$R *.DFM}
- // status bar panels
- const
- sbpMessage = 0;
- sbpCaps = 1;
- sbpPosition = 2;
- /////////// Font operations
- procedure TFormRichNote.BoldExecute(Sender: TObject);
- begin
- with RichEdit.SelAttributes do
- if fsBold in Style then
- Style := Style - [fsBold]
- else
- Style := Style + [fsBold];
- end;
- procedure TFormRichNote.ItalicExecute(Sender: TObject);
- begin
- with RichEdit.SelAttributes do
- if fsItalic in Style then
- Style := Style - [fsItalic]
- else
- Style := Style + [fsItalic];
- end;
- procedure TFormRichNote.FontExecute(Sender: TObject);
- begin
- FontDialog.Font.Assign (RichEdit.SelAttributes);
- if FontDialog.Execute then
- begin
- RichEdit.SelAttributes.Assign (FontDialog.Font);
- RichEditSelectionChange (Self);
- end;
- end;
- // right + center + left actions
- procedure TFormRichNote.ChangeAlignment(Sender: TObject);
- begin
- // change paragraph alignment using the TAlignment
- // value saved in the tag of the action
- RichEdit.Paragraph.Alignment := TAlignment (
- (Sender as TAction).Tag);
- end;
- procedure TFormRichNote.AboutExecute(Sender: TObject);
- begin
- MessageDlg (Application.Title + 'Demo' + #13#13
- + 'written for the book "Mastering Delphi" by Marco Cant