Delphi中用memo写的记事本程序.docx
《Delphi中用memo写的记事本程序.docx》由会员分享,可在线阅读,更多相关《Delphi中用memo写的记事本程序.docx(23页珍藏版)》请在三一办公上搜索。
1、Delphi中用memo写的记事本程序实验四 Delphi组件应用综合实验指导 实验目的 掌握公共对话框组件的属性、事件及应用方法。 掌握应用程序界面设计方法。 掌握基本组件的综合应用。 掌握常用函数的应用。 实验内容 设计一个文本编辑器 实验要求 参照windows记事本程序,编写类似的程序。要求应用公共对话框、菜单组件、工具栏组件、备注框组件,完成菜单设计,工具栏设计,实现文件打开、保存、关闭、文字编辑,文字格式设置等功能,保证主菜单、弹出式菜单、工具栏同步。 此编辑器主要由一个主菜单,一个工具栏,和一个快捷菜单组成,主要功能如下: 主菜单:文件,编辑,更改,关于。 工具栏:保存,新建,打
2、开,打印,字体,粗体,斜体,下划线。此工具栏是让用户更方便地使用按键。 快捷菜单:复制,剪切,黏贴。 可以自行设计其他功能,完善文本编辑器。 1、 代码实现 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ComCtrls, ImgList, ToolWin, ExtDlgs; type TForm1 = class(TForm) MainMenu1: TMainMenu; E1: TMe
3、nuItem; O1: TMenuItem; V1: TMenuItem; N3: TMenuItem; C1: TMenuItem; P2: TMenuItem; F2: TMenuItem; R1: TMenuItem; W1: TMenuItem; N4: TMenuItem; N5: TMenuItem; N1: TMenuItem; N2: TMenuItem; O2: TMenuItem; S1: TMenuItem; A1: TMenuItem; U1: TMenuItem; P1: TMenuItem; X1: TMenuItem; N6: TMenuItem; N7: TMe
4、nuItem; PopupMenu1: TPopupMenu; Edit1: TEdit; ToolBar1: TToolBar; ImageList1: TImageList; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; ToolButton4: TToolButton; ToolButton5: TToolButton; ToolButton6: TToolButton; ToolButton7: TToolButton; ToolButton8: TToolButton; To
5、olButton9: TToolButton; ToolButton10: TToolButton; ToolButton11: TToolButton; N8: TMenuItem; N9: TMenuItem; N10: TMenuItem; N11: TMenuItem; N12: TMenuItem; N13: TMenuItem; N14: TMenuItem; N15: TMenuItem; N16: TMenuItem; N17: TMenuItem; N18: TMenuItem; N19: TMenuItem; N20: TMenuItem; FontDialog1: TFo
6、ntDialog; ColorDialog1: TColorDialog; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; PrintDialog1: TPrintDialog; FindDialog1: TFindDialog; ReplaceDialog1: TReplaceDialog; PageSetupDialog1: TPageSetupDialog; Memo1: TMemo; D1: TMenuItem; L1: TMenuItem; w2: TMenuItem; procedure ToolButton8Click(Se
7、nder: TObject); procedure ToolButton9Click(Sender: TObject); procedure ToolButton10Click(Sender: TObject); procedure N11Click(Sender: TObject); procedure N12Click(Sender: TObject); procedure N15Click(Sender: TObject); procedure N16Click(Sender: TObject); procedure N17Click(Sender: TObject); procedur
8、e N18Click(Sender: TObject); procedure N19Click(Sender: TObject); procedure N3Click(Sender: TObject); procedure C1Click(Sender: TObject); procedure P2Click(Sender: TObject); procedure Memo1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, procedure N8Click(Sender: TObject); proce
9、dure N9Click(Sender: TObject); procedure N10Click(Sender: TObject); procedure ToolButton11Click(Sender: TObject); procedure ToolButton3Click(Sender: TObject); procedure ToolButton5Click(Sender: TObject); procedure P1Click(Sender: TObject); procedure A1Click(Sender: TObject); Y: Integer); procedure N
10、20Click(Sender: TObject); procedure X1Click(Sender: TObject); procedure U1Click(Sender: TObject); procedure R1Click(Sender: TObject); procedure F2Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure O2Click(Sender: TObject); proc
11、edure N2Click(Sender: TObject); procedure S1Click(Sender: TObject); procedure N14Click(Sender: TObject); procedure N13Click(Sender: TObject); procedure N5Click(Sender: TObject); procedure D1Click(Sender: TObject); procedure L1Click(Sender: TObject); / procedure N21Click(Sender: TObject); procedure F
12、indDialog1Find(Sender: TObject); procedure ReplaceDialog1Replace(Sender: TObject); procedure ReplaceDialog1Find(Sender: TObject); private Private declarations public Public declarations end; var Form1: TForm1; filename:string; implementation $R *.dfm procedure TForm1.Memo1MouseUp(Sender: TObject; Bu
13、tton: TMouseButton; Shift: TShiftState; X, Y: Integer); /鼠标选中文本,剪切,复制,等按钮才生效 begin if memo1.SelLength0 then begin n3.Enabled:=true; C1.Enabled:=true; n8.Enabled:=true; n9.Enabled:=true; D1.Enabled:=true; L1.Enabled:=true; end else begin n3.Enabled:=false; C1.Enabled:=false; n8.Enabled:=false; n9.Ena
14、bled:=false; D1.Enabled:=false; L1.Enabled:=false; end; end; procedure TForm1.N2Click(Sender: TObject); /新建 begin if (memo1.Lines.Text) then begin if MessageDlg(记事本中还有文本内容未保存,是否保存?,mtWarning,mbyes,mbno,0)=mrok then ToolButton1.Click ; end; memo1.clear; end; procedure TForm1.O2Click(Sender: TObject);
15、 /打开 begin if OpenDialog1.Execute then memo1.lines.LoadfromFile(OpenDialog1.Filename);/把在打开文件对话框中选中的文件装载到 文本框中 end; procedure TForm1.S1Click(Sender: TObject); /保存 begin if filename= then begin if savedialog1.Execute then begin memo1.Lines.SaveToFile(savedialog1.FileName); filename:=savedialog1.filen
16、ame; end end else memo1.Lines.SaveToFile(savedialog1.FileName); / 把文件保存到已打开的文本中 end; procedure TForm1.A1Click(Sender: TObject); / 另存为 begin if savedialog1.Execute then begin memo1.Lines.SaveToFile(savedialog1.FileName); filename:=savedialog1.filename; end; end; procedure TForm1.U1Click(Sender: TObje
17、ct); /页面设置? begin PagesetupDialog1.Execute; end; procedure TForm1.P1Click(Sender: TObject); /打印 begin PrintDialog1.Execute; end; procedure TForm1.X1Click(Sender: TObject); /退出 begin close; end; procedure TForm1.N3Click(Sender: TObject); /剪切 begin memo1.CutToClipboard; n3.Enabled:=false; C1.Enabled:=
18、false; n8.Enabled:=false; n9.Enabled:=false; end; procedure TForm1.C1Click(Sender: TObject); /复制 begin memo1.CutToClipboard; n3.Enabled:=false; C1.Enabled:=false; n8.Enabled:=false; n9.Enabled:=false; end; procedure TForm1.P2Click(Sender: TObject); /粘贴 begin memo1.PasteFromClipboard; end; procedure
19、TForm1.F2Click(Sender: TObject); /查找?begin /FindDialog1.Execute; /FindDialog1.Position:=Point(memo1.Left+memo1.Top,memo1.Width); /memo1.Lines.Text:=FindDialog.FindText; end; procedure TForm1.R1Click(Sender: TObject); /替换?begin ? ? ReplaceDialog1.Execute; end; procedure TForm1.N11Click(Sender: TObjec
20、t); /字体-粗体 begin if memo1.font.Style*fsbold= then begin memo1.font.Style:=memo1.Font.Style+fsbold; n11.checked:=true; ToolButton8.Down:=true; end else begin memo1.font.Style:=memo1.Font.Style-fsbold; n11.checked:=false; ToolButton8.Down:=false; end; end; procedure TForm1.N12Click(Sender: TObject); /
21、字体-斜体 begin if memo1.font.Style*fsitalic= then begin memo1.font.Style:=memo1.Font.Style+fsitalic; n12.checked:=true; ToolButton9.Down:=true; end else begin memo1.font.Style:=memo1.Font.Style-fsitalic; n12.checked:=false; ToolButton9.Down:=false; end; end; procedure TForm1.N15Click(Sender: TObject);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Delphi 中用 memo 记事本 程序
链接地址:https://www.31ppt.com/p-3060707.html