程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi在子窗口合並菜單的實現-代碼分析

Delphi在子窗口合並菜單的實現-代碼分析

編輯:Delphi

Delphi在子窗口合並菜單完整代碼:因為設計思路已經在上文中詳述,這裡只發代碼及注釋了,想參考之前的設計原理及思路,可參見這裡:Delphi在子窗口合並菜單 。

01 unit MDIFrame; 02 interface 03 uses 04 SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs, 05 Menus; 06 type 07 {略} 08 private 09 { Private declarations } 10 public 11 { Public declarations } 12 end; 13 var 14 FrameForm: TFrameForm; 15 implementation 16 uses MDIEdit; 17 {$R *.DFM} 18 procedure TFrameForm.Exit1Click(Sender: TObject); 19 begin 20 Close; 21 end//該過程關閉應用程序 22 procedure TFrameForm.New1Click(Sender: TObject); 23 begin 24 TEditForm.Create(Self); 25 end//該過程產生一個新的子窗口 26 procedure TFrameForm.Tile1Click(Sender: TObject); 27 begin 28 Tile; 29 end//該過程實現按上下左右順序重排所有子窗口 30 procedure TFrameForm.Cascade1Click(Sender: TObject); 31 begin 32 Cascade; 33 end//該過程實現相互重疊排列 34 procedure TFrameForm.Arrangeicons1Click(Sender: TObject); 35 begin 36 ArrangeIcons; 37 end//該過程實現重新排列子窗口的最小化圖表 38 procedure TFrameForm.Open1Click(Sender: TObject); 39 begin 40 if OpenFileDialog.Execute then 41 with TEditForm.Create(Self) do 42 Open(OpenFileDialog.FileName); 43 end; 44 end//該過程實現打開一個已有的文檔

編輯窗口單元文件:

vIEw source print? 001 unit MDIEdit; 002 interface 003 uses 004 SysUtils,Windows,Messages,Classes,Graphics,Controls,Forms,Dialogs, 005 Menus, StdCtrls, ComCtrls; 006 type 007 {略} 008 private 009 { Private declarations } 010 PathName: string; 011 public 012 { Public declarations } 013 procedure Open(const AFileName: string); 014 end; 015 var 016 EditForm: TEditForm; 017 const 018 DefaultFileName = ’Untitled’; 019 implementation 020 uses Clipbrd, Printers, MDIFrame; 021 {$R *.DFM} 022 procedure TEditForm.Exit1Click(Sender: TObject); 023 begin 024 FrameForm.Exit1Click(Sender); 025 end//該過程調用主窗口的退出過程,關閉整個應用程序 026 procedure TEditForm.New1Click(Sender: TObject); 027 begin 028 FrameForm.New1Click(Sender); 029 end;//該過程調用主窗口的新建過程,新建一個子窗口 030 procedure TEditForm.Open1Click(Sender: TObject); 031 begin 032 FrameForm.Open1Click(Sender); 033 end//該過程調用主窗口的打開過程,打開一個已存在的文檔 034 procedure TEditForm.AlignClick(Sender: TObject); 035 begin 036 Left1.Checked := False; 037 Right1.Checked := False; 038 Center1.Checked := False; 039 with Sender as TMenuItem do Checked := True; 040 with Editor.Paragraph do 041 if Left1.Checked then 042 Alignment := taLeftJustify 043 else if Right1.Checked then 044 Alignment := taRightJustify 045 else if Center1.Checked then 046 Alignment := taCenter; 047 end;//該過程實現文字的對齊方式控制 048 procedure TEditForm.Wordwrap1Click(Sender: TObject); 049 begin 050 with Editor do 051 begin 052 WordWrap := not WordWrap; { toggle Word wrapping } 053 if WordWrap then 054 ScrollBars := ssVertical 055 else 056 ScrollBars := ssBoth; 057 WordWrap1.Checked := WordWrap; { set menu item check } 058 end; 059 end//該過程設置子窗口的文字能不能自動換行 060 procedure TEditForm.Cut1Click(Sender: TObject); 061 begin 062 Editor.CutToClipboard; 063 end;//該過程實現剪切功能 064 procedure TEditForm.Copy1Click(Sender: TObject); 065 begin 066 Editor.CopyToClipboard; 067 end//該過程實現拷貝功能 068 procedure TEditForm.Paste1Click(Sender: TObject); 069 begin 070 Editor.PasteFromClipboard; 071 end//該過程實現粘貼功能 072 procedure TEditForm.Selectall1Click(Sender: TObject); 073 begin 074 Editor.SelectAll; 075 end//該過程實現全選功能 076 procedure TEditForm.Delete1Click(Sender: TObject); 077 begin 078 Editor.ClearSelection; 079 end//該過程實現刪除所選文本功能 080 procedure TEditForm.Edit1Click(Sender: TObject); 081 var 082 HasSelection: Boolean; 083 begin 084 Paste1.Enabled := Clipboard.HasFormat(CF_TEXT); 085 Paste2.Enabled := Paste1.Enabled; 086 HasSelection := Editor.SelLength > 0; 087 Cut1.Enabled := HasSelection; 088 Cut2.Enabled := HasSelection; 089 Copy1.Enabled := HasSelection; 090 Copy2.Enabled := HasSelection; 091 Delete1.Enabled := HasSelection; 092 end;//該過程初始化Edit 菜單下的子菜單 093 procedure TEditForm.Open(const AFileName: string); 094 begin 095 PathName := AFileName; 096 Caption := ExtractFileName(AFileName); 097 with Editor do 098 begin 099 Lines.LoadFromFile(PathName); 100 SelStart := 0; 101 ModifIEd := False; 102 end; 103 end;//該過程實現打開功能 104 procedure TEditForm.Saveas1Click(Sender: TObject); 105 begin 106 SaveFileDialog.FileName := PathName; 107 if SaveFileDialog.Execute then 108 begin 109 PathName := SaveFileDialog.FileName; 110 Caption := ExtractFileName(PathName); 111 Save1Click(Sender); 112 end; 113 end;//該過程實現另存為功能 114 procedure TEditForm.Save1Click(Sender: TObject); 115 begin 116 if PathName = DefaultFileName then 117 SaveAs1Click(Sender) 118 else 119 begin 120 Editor.Lines.SaveToFile(PathName); 121 Editor.ModifIEd := False; 122 end; 123 end//該過程實現保存功能 124 procedure TEditForm.Font1Click(Sender: TObject); 125 begin 126 FontDialog1.Font := Editor.Font; 127 if FontDialog1.Execute then 128 Editor.SelAttributes.Assign(FontDialog1.Font); 129 end//該過程實現設置字體功能 130 procedure TEditForm.Close1Click(Sender: TObject); 131 begin 132 Close; 133 end//該過程實現關閉子窗口功能 134 procedure TEditForm.FormClose(Sender: TObject; var Action: TCloseAction); 135 begin 136 Action := caFree; 137 end//該過程實現釋放子窗口所占內存功能 138 procedure TEditForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); 139 const 140 SWarningText = ’Save changes to %s?’; 141 begin 142 if Editor.ModifIEd then 143 begin 144 case MessageDlg(Format(SWarningText,[PathName]),mtConfirmation, 145 [mbYes,mbNo,mbCancel],0of 146 idYes: Save1Click(Self); 147 idCancel: CanClose := False; 148 end; 149 end; 150 end//該過程保證安全退出子窗口,而不丟失未保存的文件 151 procedure TEditForm.FormCreate(Sender: TObject); 152 begin 153 PathName := DefaultFileName; 154 end;//該過程初始化子窗口的文件名和文件保存路徑 155 procedure TEditForm.Printersetup1Click(Sender: TObject); 156 begin 157 PrinterSetupDialog1.Execute; 158 end//該過程提供打印對話框 159 procedure TEditForm.Print1Click(Sender: TObject); 160 begin 161 if PrintDialog1.Execute then 162 Editor.Print(PathName); 163 end;//該過程打印當前文件 164 end.
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved