RichForm.pas
资源名称:delphi.rar [点击查看]
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:13k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit RichForm;
- interface
- uses
- SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, ExtCtrls, Menus, ActnList, ToolWin, ImgList, ClipBrd,
- RichEdit, AppEvnts;
- type
- TFormRichNote = class(TForm)
- FontDialog: TFontDialog;
- MainMenu: TMainMenu;
- File1: TMenuItem;
- Open1: TMenuItem;
- Saveas1: TMenuItem;
- Exit1: TMenuItem;
- Font1: TMenuItem;
- Bold1: TMenuItem;
- Italic1: TMenuItem;
- Paragraph1: TMenuItem;
- LeftAligned1: TMenuItem;
- Centered1: TMenuItem;
- RightAligned1: TMenuItem;
- Help1: TMenuItem;
- About1: TMenuItem;
- OpenDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- More1: TMenuItem;
- ColorDialog: TColorDialog;
- ActionList: TActionList;
- acCentered: TAction;
- acUndo: TAction;
- acCut: TAction;
- acPaste: TAction;
- acCopy: TAction;
- acBold: TAction;
- acItalic: TAction;
- acRightAligned: TAction;
- acLeftAligned: TAction;
- acSave: TAction;
- Undo1: TMenuItem;
- acFont: TAction;
- acCountChars: TAction;
- Images: TImageList;
- SizeMenu: TPopupMenu;
- Small1: TMenuItem;
- Medium1: TMenuItem;
- Large1: TMenuItem;
- acHintColor: TAction;
- HintColor1: TMenuItem;
- ControlBar: TControlBar;
- ToolBarFile: TToolBar;
- ToolButton1: TToolButton;
- ToolButton2: TToolButton;
- ToolButton3: TToolButton;
- ToolButton20: TToolButton;
- ToolButton4: TToolButton;
- ToolButton10: TToolButton;
- ToolButton11: TToolButton;
- ToolButton13: TToolButton;
- ToolButton14: TToolButton;
- ToolButton15: TToolButton;
- ToolButton16: TToolButton;
- ToolButton12: TToolButton;
- ToolButton17: TToolButton;
- ToolBarEdit: TToolBar;
- ToolBarFont: TToolBar;
- ComboFont: TComboBox;
- ToolButton6: TToolButton;
- ToolButton7: TToolButton;
- ToolButton8: TToolButton;
- ToolButton9: TToolButton;
- BarMenu: TPopupMenu;
- ToolBarMenu: TToolBar;
- StatusBar: TStatusBar;
- acExit: TAction;
- ApplicationEvents1: TApplicationEvents;
- ColorBox1: TColorBox;
- Panel1: TPanel;
- ControlBarLower: TControlBar;
- RichEdit: TRichEdit;
- 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