Delphi高仿windows记事本源码
用delphi7编写windows服务程序
⽤delphi7编写windows服务程序⽤delphi7编写windows服务程序总结⼀、服务程序的创建delphi编写服务程序⾮常简单,点击菜单File->New->Other->New属性页->Service Application,系统⾃动会创建基本的代码。
这⾥需要说明的是,在“New属性页”中还有⼀个Service,这个Service和Service Application还是有区别的,应该说Service Application的范围⼤,它可以包含⼏个Service。
⼀个Service Application可以创建⼏个Service,service继承⾃TService,界⾯表现和TDataModel类似,做过数据库的朋友肯定都不陌⽣,区别是TDataModel是⽤来放数据库连接及操作组件的容器,⽽TService则是可以存放很多没有界⾯的组件,如indy的IDtcpclient等。
⼆、重要属性及事件说明属性:DisplayName 显⽰名称Name 名称,当你⽤命令提⽰符来启动、停⽌服务时,就需要⽤到Interactive 与界⾯交互的选项事件:OnCreate:类似于Tform的OnCreateOnDestroy:类似于Tform的OnDestroyOnExecute:⾮常重要,⼀般写成下⾯while not Terminated dobeginSleep(10);ServiceThread.ProcessRequests(False);end;OnPause:服务暂停OnShutdown:不太清楚OnStart:服务启动,重要OnStop:服务停⽌,重要三、服务的依赖关系因为我的服务是要连接数据库的,所以必须要等sql server的服务起来之后,我才能起来,这样才能连接数据库,因此这⾥⾯有个依赖关系的问题。
可以在属性Dependencies 中增加⼀项,选择MSSQLSERVER。
(完整word版)简单Java仿windows记事本
主程序:import java.awt。
*;import java.awt.datatransfer.*;import java。
awt。
event.*;import javax。
print。
*;import javax.print。
attribute。
DocAttributeSet;import javax.print.attribute.HashDocAttributeSet;import javax.print.attribute.HashPrintRequestAttributeSet;import javax.print.attribute.PrintRequestAttributeSet;import javax。
print.attribute.standard.MediaSizeName; import javax.swing。
*;import javax.swing.border。
BevelBorder;import javax。
swing。
event。
UndoableEditEvent;import javax。
swing。
event。
UndoableEditListener;import javax。
swing.filechooser.*;import javax.swing.filechooser。
FileFilter;import javax。
swing。
plaf.FileChooserUI;import javax。
swing.undo.UndoableEdit;import java.io.*;public class Notepad extends JFrame {/***@param args*/public JTextArea jta=null;//中间的文本区域private File selectedFile=null;private JFileChooser chooser=null;//文件选择器private UndoableEdit edit; //设置还原功能private boolean canUndo=false;private JMenuItem jmiUndoItem;//撤销的菜单private Clipboard clip=null;//粘贴板private JDialog jdSearchDialog;public Notepad(){super(”Notepad Beta”);super。
Delphi高仿windows记事本源码
主要功能都已添加上并测试可用。
效果图:源码:unit Unit1Calculator;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ComCtrls;typeTForm1 = class(TForm)ColorDialog1: TColorDialog;SaveDialog1: TSaveDialog;ColorDialog2: TColorDialog;MainMenu1: TMainMenu;N1: TMenuItem;myNew: TMenuItem;mySave: TMenuItem;N3: TMenuItem;myPage: TMenuItem;myPrint: TMenuItem;myQuit: TMenuItem;myEdit: TMenuItem;myUndo: TMenuItem;N4: TMenuItem;myCut: TMenuItem;myCopy: TMenuItem;myPaste: TMenuItem;myDelete: TMenuItem;N6: TMenuItem;myFind: TMenuItem;myReplace: TMenuItem;myFormat: TMenuItem;myFont: TMenuItem;myView: TMenuItem;myStatus: TMenuItem;myHelp: TMenuItem;myHelpTopics: TMenuItem;N9: TMenuItem;myAbout: TMenuItem;OpenDialog1: TOpenDialog;FontDialog1: TFontDialog;myOpen: TMenuItem;FindDialog1: TFindDialog;ReplaceDialog1: TReplaceDialog;FontDialog2: TFontDialog;PageSetupDialog1: TPageSetupDialog;PrintDialog1: TPrintDialog;RichEdit1: TRichEdit;procedure myNewClick(Sender: TObject);procedure FormCreate(Sender: TObject);procedure myOpenClick(Sender: TObject);procedure mySaveClick(Sender: TObject);procedure myQuitClick(Sender: TObject);procedure myUndoClick(Sender: TObject);procedure myCutClick(Sender: TObject);procedure myCopyClick(Sender: TObject);procedure myPasteClick(Sender: TObject);procedure myDeleteClick(Sender: TObject);procedure myFindClick(Sender: TObject);procedure myReplaceClick(Sender: TObject);procedure myFontClick(Sender: TObject);procedure myPageClick(Sender: TObject);procedure myPrintClick(Sender: TObject);procedure myAboutClick(Sender: TObject);procedure myHelpTopicsClick(Sender: TObject);procedure FormClose(Sender: TObject; var Action: TCloseAction); private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}var fName: String;procedure TForm1.myNewClick(Sender: TObject);var msg : integer;beginif (richEdit1.Modified) thenbeginmsg := Application.MessageBox('文件已被修改,是否保存?', 'Delphi记事本', mb_YesNoCancel);case msg ofidYes: beginmySaveClick(Sender);richEdit1.Clear;fName := '文档1';Caption := fName + '--Delphi记事本';end;idNo: beginrichEdit1.Clear;fName := '文档1';Caption := fName + '--Delphi记事本';end;idCancel: ;end;endelse beginrichEdit1.Clear;fName := '文档1';Caption := fName + '--Delphi记事本';end;end;procedure TForm1.FormCreate(Sender: TObject);beginfName := '文档1';richEdit1.Clear;Caption := fName + '--Delphi记事本';end;procedure TForm1.myOpenClick(Sender: TObject);var msg : integer;beginif (richEdit1.Modified) thenbeginmsg := Application.MessageBox('文件已被修改,是否保存?', 'Delphi记事本', mb_YesNoCancel);case msg ofidYes: beginmySaveClick(Sender);end;idNo: if (openDialog1.Execute) thenbeginfName := openDialog1.FileName;richEdit1.Lines.LoadFromFile(fName);form1.Caption := fName + 'Delphi记事本';end;idCancel: ;end;endelse if (openDialog1.Execute) thenbeginfName := openDialog1.FileName;richEdit1.Lines.LoadFromFile(fName);form1.Caption := fName + 'Delphi记事本';end;end;procedure TForm1.mySaveClick(Sender: TObject);beginif (fName <> '文档1') thenbeginrichEdit1.Lines.SaveToFile(fName);endelse beginsaveDialog1.FileName := fName;if (saveDialog1.Execute) thenbeginfName := saveDialog1.FileName;richEdit1.Lines.SaveToFile(fName);form1.Caption := fName;end;end;richEdit1.Modified := false;end;procedure TForm1.myQuitClick(Sender: TObject);beginif (richEdit1.Modified) then mySaveClick(Sender); Application.Terminate;end;procedure TForm1.myUndoClick(Sender: TObject);beginrichEdit1.Undo;end;procedure TForm1.myCutClick(Sender: TObject);beginrichEdit1.CutToClipboard;end;procedure TForm1.myCopyClick(Sender: TObject);beginrichEdit1.CopyToClipboard;end;procedure TForm1.myPasteClick(Sender: TObject);beginrichEdit1.PasteFromClipboard;end;procedure TForm1.myDeleteClick(Sender: TObject);beginrichEdit1.ClearSelection;end;procedure TForm1.myFindClick(Sender: TObject);beginfindDialog1.Execute;end;procedure TForm1.myReplaceClick(Sender: TObject);beginreplaceDialog1.Execute;end;procedure TForm1.myFontClick(Sender: TObject);beginfontDialog1.Font := richEdit1.Font; //初始化字体对话框if (fontDialog1.Execute) then richEdit1.SelAttributes.Assign(fontDialog1.Font); end;procedure TForm1.myPageClick(Sender: TObject);beginpageSetupDialog1.Execute;end;procedure TForm1.myPrintClick(Sender: TObject);beginif (printDialog1.Execute) thenbeginrichEdit1.Print(fName);end;end;procedure TForm1.myAboutClick(Sender: TObject);beginShowMessage('Delphi记事本1.0' + #13 + ' 记念于12.5.14');end;procedure TForm1.myHelpTopicsClick(Sender: TObject);beginmyAboutClick(Sender);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); beginmyQuitClick(Sender);end;end.。
delphi记事本开发
Delphi程序设计第三节模仿制作windows 计算器首先:我们设置FORM1的窗口属性这样窗口就不可以随便拉大拉小了!用选中计算器的图标!把FORM1的caption属性设置为模仿的windows 计算器。
画一个EDIT组建(),并把他的TEXT属性里的字删除!使TEXT里边显示为空!好了,画好了,我们接着来画面板!点一下(panel)该组件只是为了好看没有多大的实际用途!拉到适当的大小的时候我们来设置他的属性!首先,我们把他的这个属性清空,是面板上不显示字!把设置为使面板下沉我们再画18个快速按钮,分别把CAPTION属性设置成如图好了,到此,我们的界面就画完了!我们先来讲讲本节用到的组件属性!Form1.caption (代表是FORM1的标题文本),我们可以在属性页里设置也可以用语句设置;Delphi里所有的组件属性都可以用语句设置,以后我就不重复了!例:form1.caption:=’哈哈,测试一下!’; //这时候则form1的标题为哈哈,测试一下!Edit1.text:=’看看你聪明不!’;//这时候edit1里边显示的文本为看看你聪明不!Panel 面板组件,无实际用途,主要用于界面美观·!Speedbutton 快速按钮!主要属性:checked 设置是否被选中flat 设置是否为OFFICE 2000风格Down 设置是否按下好了,接下来我们写代码!重点难点解析:edit1.text:=edit1.text + '1'; 此句话的意思是代表在原来的字符串后面加个字符串1例:假如说原来的edit1.text 为字符串123456 在执行上面的语句的话,edit1.text 的值则为1234561speedbutton12.caption = '关闭' 注意:等于号在Delphi中代表比较的意思,就是说此句的意思是比较speedbutton12.caption 的值和字符串关闭是不是相等的!case flag of1:temp2:=strtofloat(edit1.text)+ strtofloat(temp1);2:temp2:=strtofloat(temp1) - strtofloat(edit1.text);3:temp2:=strtofloat(edit1.text)* strtofloat(temp1);4:temp2:strtofloat(temp1) / strtofloat(edit1.text);end;edit1,text:=floattostr(temp2);strtofloat 把字符串转换为浮点数floattostr 和上面的相反case flag of 当FLAG的值和下面的符合时运行后面的表达式…..。
利用Delphi编写Windows控制面板组件及实例
利用Delphi编写Windows 控制面板组件及实例张建军(中国人民解放军合肥炮兵学院研究生系97级)韩莹(中保财险安徽省铜陵市分公司计财部)关键词:在windows95/Nt/98操作系统中,控制面板(controlpanel)提供了定制windows的操作方法,通过它可以完成设置打印机、显示、网络、添加新硬件等功能。
通常控制面板包含20多个组件(*.cpL),分别负责系统某一方面的设置。
鼠标双击任一组件图标,控制面板调用相应程序,弹出对话框,允许设置系统参数。
确认修改后系统参数保存在windows注册表或某一配置文件(*.INI)中。
一、控制面板组件基础知识控制面板是一个windows应用程序c:\wINDowS\coNtRoL.ExE,其配置文件是c:\wINDowS\coNtRoL.INI.控制面板组件是一些动态链接库,其扩展名不是DLL,而是cpL.通常,控制面板组件保存在c:\wINDowS\SyStEm\目录下。
在coNtRoL.INI中有一个[mmcpL]节,该节可指定由coNtRoL.ExE调用的动态链接库,其格式一般为:…[mmcpL]uniqueName=D:\pRoJEct1.DLL(这里假设pRoJEct1为用户编写的控制面板组板文件名,其访问路径可由读者自行确定)…采用此方法,pRoJEct1.DLL不必存放在c:\wINDowS\SyStEm\目录下,扩展名不必改为cpL.coNtRoL.ExE运行后按以下顺序调用这些动态链接库:在c:\wINDowS\SyStEm\目录下调用mAIN.INI.已加载并输出cplApplet()函数的可安装驱动程序。
在coNtRoL.INI[mmcpL]节中指定的DLL.在c:\wINDowS\SyStEm\目录下调用cpL.因此,编写控制面板组件近似于编写普通DLL.通常一个cpL支持控制面板中的一个组件(即一个图标),也可支持多个组件。
分享一个Delphi制作的文档编辑器源代码(仿Word)
分享⼀个Delphi制作的⽂档编辑器源代码(仿Word)
功能挺多的,就是很多地⽅都没有完善。
不过简单使⽤,是没有问题的。
我也忘记是在哪个⽹站下载的,可能是Git国外的⽹站。
仿Word⽂档编辑器,不过其实没有必要的,因为⽤户会直接使⽤微软或者其他软件来制作⾃⼰的⽂档。
但是却具有参考价值,虽然代码需要优化的地⽅还有很多。
⽐如那些添加控件这些可以去除,把代码结构处理得紧凑⼀些,⽽且增加更多可以⾃定义的地⽅就更理想了。
其实⼤家最最讨厌都是⼀些滚动条和控件背景颜⾊都⽆法⾃定义,都被写得死死的,就像原来Vcl那些玩意⼀样。
想弄个⾃定义界⾯都办不到。
这套代码也是这样,所以需要⼤家⾃⼰改。
下⾯这个是我改的,多页功能,我去掉了,改成单页,跟RichEdit这种类型⼀样。
不过完全⽀持表格、图⽚、GIF图⽚这些添加,⽽且可以⾃定义编辑框背景图⽚的添加和更换。
这样⼀来,也算是解决了⼀直以来的⼼愿。
⾄少收集和管理各种⽂档资料更加⽅便了。
在这⾥提供原来代码的下载地址,原来的忘记了:
有兴趣的,⾃⼰下载看看,⾄于我改的就不提供了。
它⾥⾯带有作者的通讯⽅式,有兴趣可以联系交流。
记事本源码
Private Sub Command1_Click()
Web1.Navigate2 Url.text
End Sub
Private Sub Command10_Click()
Web2.Navigate2 ""
End Sub
Private Sub Command7_Click()
Txt.FontItalic = Common.FontItalic
Txt.FontName = Common.FontName
Txt.FontSize = Common.FontSize
End Sub
Private Sub Form_Load()
'初始化StatusBar1中的时间显示
Loop
text = st
Txt.text = text
End Sub
'删除所有行首空格
Private Sub DelSK_Click()
Dim text As String, s As String, i As Integer, j As Integer
text = Txt.text
ZhanTie.Enabled = True
End Sub
'删除选中的文本
Private Sub Delect_Click()
Txt.SelText = ""
End Sub
'删除全部空行
Private Sub DelKH_Click()
Dim text As String, s As String, st As String
仿windowsJAVA课程设计汇本记事本
前言随时着科学技术的快速发展,计算机程序设计早已成为了趋势,JAVA是计算机专业的核心课程,是计算机科学的算法理论基础和软件设计的技术基础。
JAVA是实践性很强的课程。
课程设计是加强实践能力的一个强有力手段。
要求掌握JAVA的应用、编写、上机调试的基本方法。
本课程设计就是主要利用java语言编写的一个模仿windows 记事本的较简单的程序,实现了一些基本功能,要求打开文件,读取文件中的文本信息;显示、编辑修改文本信息;实现输入文本文件、控制保存文本信息到指定的文件的功能。
目录一、需求分析 (1)二、概要设计 (1)三、详细设计 (2)四、系统调试分析 (6)五、课程设计心得体会 (7)六、使用说明 (7)七、参考文献及致谢 (7)八、附录(程序源代码) (7)一、需求分析该课程设计报告里的简易记事本程序是使用Java程序设计语言编写的,要求实现记事本的基本功能,参考了windows中记事本的一些功能。
要求打开文件,读取文件中的文本信息;显示、编辑修改文本信息;实现新建、打开、保存文本文件以及控制保存文本信息到指定的文件的一些基本功能。
二、概要设计1.1 系统主要功能本程序是利用java程序设计语言编写的一个简单的记事本程序。
可以通过菜单栏和工具栏实现以下功能:如文件的新建,打开,保存和退出;对文件的编辑,如复制,剪切,粘贴;以及帮助菜单;执行完操作后,能够顺利关闭记事本。
1.2运行环境要求(1) 实现设计的系统硬件需求硬件配置的基本要求:* 586以上的计算机* 32MB以上的内存* 彩色显示器* 3.5寸高密软盘驱动器* 光盘驱动器* 4G以上硬盘空间* 鼠标(2) 实现设计的系统软件* WINDOWS95或WINDOWS98* Jcreator Pro全套软件三、详细设计设计思路:设计一个EditorDemo类,继承自JFrame类,并在EditorDemo类利用JtextPane创建面板窗口textPane,利用Jlabel创建状态栏statusBar,利用JFileChooser 创建文件选择器filechooser,利用JMenuBar创建并实例化菜单栏,利用JToolBar创建工具栏,再通过一些具体方法实现各功能键的功能。
Delphi直接用WindowsAPI编程讲解
Delphi程序员往往习惯了用VCL元件编程,其实Delphi也能进行基于WINDOWS API SDK的编程。
而且用Delphi在某些方面效果似乎比用VisualC++效果还要好。
比如本例程,用Delphi 6编译出来只有9216字节(9k)而同样的Visual C++程序却有16896字节(17k)。
(此例程是笔者从网上下载的c++源码例程,其中有c源程序,和编译好的.exe文件。
源代码经笔者改写成Delphi代码。
)这证明Delphi编译器的优化效果非常好。
API是(Application Programming Interface)的缩写,意为应用编程界面,它包含了编写Windows所有函数、数据类型。
VCL就是以它为基础进行封装的,它是应用程序在Windows 上运行的基础。
通过熟悉使用WINDOWS API SDK直接编制WINDOWS程序,程序员将对WINDOWS的执行机制有更深入的了解,从而编写出更高效、实用的程序。
下面是我们用API函数建立的第一个程序:1 : program HELLOWIN;2 :3 : uses4 : windows, Messages ,mmsystem;5 :6 :7 :8 : var9 : sz_appname:array [0..8] of char='HelloWin'#0;10 : Win_Class: WNDCLASSEX; //窗口类11 : w_Handle,inst:HWND;//w_Handle窗口句柄、程序句柄12 : w_msg:TMSG; //消息数据13 :14 : function WindowProc(h_Wnd,u_Msg,w_Param,l_Param: LONGINT):LRESULT;stdcall;15 : //回调函数16 : var p_hdc:hdc;17 : p_rect:trect;18 : ps : PAINTSTRUCT ;19 : begin20 :21 :22 : case u_msg of23 : WM_DESTROY : PostQuitMessage (0);24 : WM_CREATE : PlaySound (pchar('hellowin.wav'#0), 0, SND_FILENAME or SND_ASYNC) ;25 : WM_PAINT :begin26 : p_hdc := BeginPaint (h_wnd, ps) ;27 : GetClientRect (h_wnd, p_rect);28 : DrawText (p_hdc, pchar('Hello, Windows!'#0), -1, p_rect,29 : DT_SINGLELINE or DT_CENTER or DT_VCENTER) ;30 : EndPaint (h_wnd, ps) ;31 : end;32 :33 : end;34 : Result := DefWindowProc(h_Wnd, u_Msg, w_Param, l_Param);35 : end;36 :37 :38 :39 :40 : begin41 : Inst := hInstance;42 : win_class.cbSize := sizeof (win_class) ;43 : win_class.style := CS_HREDRAW or CS_VREDRAW ;44 : win_class.lpfnWndProc := @WindowProc ;45 : win_class.cbClsExtra := 0 ;46 : win_class.cbWndExtra := 0 ;47 : win_class.hInstance := Inst ;48 : win_class.hIcon := LoadIcon (0, IDI_APPLICATION) ;49 : win_class.hCursor := LoadCursor (0, IDC_ARROW) ;50 : win_class.hbrBackground := HBRUSH (GetStockObject (WHITE_BRUSH)) ;51 : win_class.lpszMenuName := nil ;52 : win_class.lpszClassName := @sz_AppName ;53 : win_class.hIconSm := LoadIcon (0, IDI_APPLICATION) ;54 : RegisterClassEx(Win_Class);55 : w_Handle:=CreateWindow(@sz_appname, pchar('The Hello Program'#0),56 : WS_OVERLAPPEDWINDOW,200,200,300,300,0,0,57 : Inst,nil) ;58 :59 : ShowWindow (w_Handle, SW_SHOWNORMAL) ;60 : UpdateWindow(w_Handle);61 :62 :63 : while(GetMessage(w_msg, 0, 0, 0)) do64 : begin65 : TranslateMessage(w_msg);66 : DispatchMessage(w_msg);67 : end;68 :69 :70 : end.以上源程序读者可以直接拷贝到记事本中,把行标去掉后另存为.dpr文件,然后用Delphi直接打开,就可以编译运行,之后你就会听到电脑向你发出的问候。
用Delphi编写Windows服务程序
一、Windows服务简介服务程序(Service Application)是一种运行于WinNT的后台程序,每个服务程序(Service Application)中可能包含若干个服务(Service),每个服务就是其中的一个线程(该服务也可以创建多个子线程)。
采用服务,应用程序可以获得特殊的权限,而且不会被用户通过Win2000的任务管理器直接结束程序,所以服务常常用来实现一些特殊的目标。
通过Win2000控制面板中的服务管理工具,我们可以设置/查看服务的特性:(1)服务名称;(2)显示名称;(3)描述;(4)启动类型;(5)依赖关系;其中,服务名称是标识给服务的。
以Win2000的C:\WINNT\System32\程序为例子,该Exe文件对应一个Service Application,是该服务程序的可见实体;该exe中包含多个服务(Service),例如Alerter,Dhcp(DHCP Client),Messenger等。
当我们结束一个服务的时候,该服务所在的Service Application 中的其他服务并没有被终止。
在Delphi中,Borland的工程师为我们提供了TServiceApplication,TService,TServiceThread等类,封装了大量细节,简化了服务程序的。
二、TServiceApplication在Delphi中,类TServiceApplication就对应上述的ServiceApplication。
利用Delphi的开发环境,我们新建一个Service Application Project,同时就创建了一个继承自TService的类。
项目文件中的Application对象就是一个TServiceApplication实例。
每个TServiceApplication包含若干个TService对象,正好对应上述的服务程序和服务之间的数量关系。
Windows的记事本源代码
bw.close();
}
}
class MyClipboard{//剪贴板的应用
private Clipboard cb;
public MyClipboard(){
cb=Toolkit.getDefaultToolkit().getSystemClipboard();
}
public void setData(String data)throws Exception{//保存文件
fDlg.setTitle("保存");
fDlg.setMode(FileDialog.SAVE);
fDlg.setVisible(true);
BufferedWriter bw=new BufferedWriter(new FileWriter(getPath()));
private FileDialog fDlg;
public MyFile(Frame parent){
fDlg=new FileDialog(parent,"",FileDialog.LOAD);
}
private String getPath(){//获得打开文件的路径
return fDlg.getDirectory()+"\\"+fDlg.getFile();
}
public void addMenuItems(int menuNumber,String[]items){//添加菜单中的子项菜单或分隔符
for(int i=0;i<items.length;i++){
记事本和资源管理器源码
记事本源码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication2{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e) {Display();this.toolStripStatusLabel1.Text = "当前时间:" +DateTime.Now.ToString();}private void Display(){this.textBox1.Visible = false;this.tsm_copy.Enabled = false;this.tsp_zt.Enabled = false;this.tsm_jq.Enabled = false;this.tsp_zt.Enabled = false;}private void toolStripLabel1_Click(object sender, EventArgs e){File_New();}private void File_New(){this.textBox1.Text = "";this.textBox1.Visible = true;this.tsm_copy.Enabled = true;this.tsp_zt.Enabled = true;this.tsm_jq.Enabled = true;this.tsp_zt.Enabled = true;}private void打开OToolStripMenuItem_Click(object sender, EventArgs e) {File_New();string path = "";OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "(文本文件)*.txt|*.txt";ofd.Title = "打开";if (ofd.ShowDialog()==DialogResult.OK){path = ofd.FileName;}else{return;}StreamReader sr = new StreamReader(path, Encoding.Default);this.textBox1.Text = sr.ReadToEnd();sr.Close();}private void关闭CToolStripMenuItem_Click_1(object sender, EventArgs e){Application.Exit();}private void保存ToolStripMenuItem_Click(object sender, EventArgs e) {string path = "";SaveFileDialog sfd = new SaveFileDialog();sfd.Filter = "(文本文件)*.txt|*.txt";sfd.Title = "保存";if (sfd.ShowDialog()==DialogResult.OK){path = sfd.FileName;}else{return;}StreamWriter sw = new StreamWriter(path,true,Encoding.UTF8);sw.Write(textBox1.Text);sw.Flush();sw.Close();}private void tsm_copy_Click(object sender, EventArgs e){if (this.textBox1.SelectedText!=""){Clipboard.SetText(this.textBox1.SelectedText);}}private void tsp_zt_Click(object sender, EventArgs e){this.textBox1.AppendText(Clipboard.GetText());}private void tsm_jq_Click(object sender, EventArgs e){if (this.textBox1.SelectedText!=""){Clipboard.SetText(textBox1.SelectedText);this.textBox1.SelectedText = "";}}private void tsm_del_Click(object sender, EventArgs e){this.textBox1.SelectedText = "";}private void字体ToolStripMenuItem_Click(object sender, EventArgs e) {if (fontDialog1.ShowDialog()==DialogResult.OK){this.textBox1.Font = fontDialog1.Font;}}private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e){}private void toolStripButton1_Click(object sender, EventArgs e){File_New();string path = "";OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = "(文本文件)*.txt|*.txt";ofd.Title = "打开";if (ofd.ShowDialog() == DialogResult.OK){path = ofd.FileName;}else{return;}StreamReader sr = new StreamReader(path, Encoding.Default);this.textBox1.Text = sr.ReadToEnd();sr.Close();}private void toolStripButton2_Click(object sender, EventArgs e){string path = "";SaveFileDialog sfd = new SaveFileDialog();sfd.Filter = "(文本文件)*.txt|*.txt";sfd.Title = "保存";if (sfd.ShowDialog() == DialogResult.OK){path = sfd.FileName;}else{return;}StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8); sw.Write(textBox1.Text);sw.Flush();sw.Close();}private void toolStripLabel2_Click(object sender, EventArgs e){}private void复制ToolStripMenuItem1_Click(object sender, EventArgs e) {if (this.textBox1.SelectedText != ""){Clipboard.SetText(this.textBox1.SelectedText);}}private void粘贴ToolStripMenuItem1_Click(object sender, EventArgs e) {this.textBox1.AppendText(Clipboard.GetText());}private void帮助HToolStripMenuItem_Click(object sender, EventArgs e) {}private void视图VToolStripMenuItem_Click(object sender, EventArgs e) {}private void格式OToolStripMenuItem_Click(object sender, EventArgs e) {}private void新建NCtrlNToolStripMenuItem_Click(object sender, EventArgs e){File_New();}}}资源管理器源码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace Demo7.HomeWork{public partial class ResMgrForm : Form{int newfileCount = 1;int newFolderCount = 1;int operatinFlag = 0;//0表示新建文件,1表示新建文件夹,2表示重命名public ResMgrForm(){InitializeComponent();}#region EventOperation//private void tv_Dirs_AfterSelect(object sender, TreeViewEventArgs e) {ShowSelectedNode();}//private void ResMgrForm_Load(object sender, EventArgs e){InitialResMgr();}//private void tsMenuItem_BackToLastLayer_Click(object sender, EventArgs e){BackToLastLayer();}//private void tsMenuItem_Delete_Click(object sender, EventArgs e){Delete();}//private void tsMenuItem_NewPath_Click(object sender, EventArgs e){NewPath();operatinFlag = 1;}//private void tsMenuItem_NewFile_Click(object sender, EventArgs e) {NewFile();operatinFlag = 0;}//private void tsMenuItem_Rename_Click(object sender, EventArgs e) {if (lv_DirsAndFiles.SelectedItems.Count > 0){lv_belEdit = true;lv_DirsAndFiles.SelectedItems[0].BeginEdit();operatinFlag = 2;}}#endregion#region Functionprivate void InitialResMgr(){string[] drives = Directory.GetLogicalDrives();for (int i = 0; i < drives.Length; i++){tv_Dirs.Nodes.Add(new TreeNode(drives[i], 0, 0));}if (tv_Dirs.Nodes.Count > 0)tv_Dirs.SelectedNode = tv_Dirs.Nodes[0];}//节点被选中时更新控件private void ShowSelectedNode(){string[] dirs =Directory.GetDirectories(tv_Dirs.SelectedNode.FullPath);TreeNode[] nodes =newTreeNode[ tv_Dirs.SelectedNode.Nodes.Count];tv_Dirs.SelectedNode.Nodes.CopyTo(nodes,0);//更新treeview控件for (int i = 0; i < dirs.Length; i++){string text = dirs[i].Substring(dirs[i].LastIndexOf('\\') + 1, dirs[i].Length - dirs[i].LastIndexOf('\\')-1);TreeNode existNode =nodes.SingleOrDefault<TreeNode>(s=>s.Text==text);if (existNode == null)//判断节点是否存在{tv_Dirs.SelectedNode.Nodes.Add(new TreeNode(text,1,1)); }}//更新listview控件string[]filesAndDirs=Directory.GetFileSystemEntries(tv_Dirs.SelectedNode.FullPath); lv_DirsAndFiles.Items.Clear();lv_DirsAndFiles.BeginUpdate();int imagindex=1;for (int j = 0; j < filesAndDirs.Length; j++){if (Directory.Exists(filesAndDirs[j])){imagindex = 1;}else{imagindex = 2;}ListViewItem lvi = new ListViewItem();lvi.Text =filesAndDirs[j].Substring(filesAndDirs[j].LastIndexOf('\\') + 1, filesAndDirs[j].Length - filesAndDirs[j].LastIndexOf('\\') - 1); ;lvi.ImageIndex = imagindex;lv_DirsAndFiles.Items.Add(lvi);}lv_DirsAndFiles.EndUpdate();}//打开(文件或目录)操作private void tsMenuItem_Open_Click(object sender, EventArgs e){if (lv_DirsAndFiles.SelectedItems.Count > 0){if (lv_DirsAndFiles.SelectedItems[0].ImageIndex == 1){TreeNode[] nodes = newTreeNode[tv_Dirs.SelectedNode.Nodes.Count];tv_Dirs.SelectedNode.Nodes.CopyTo(nodes, 0);string selectItem =lv_DirsAndFiles.SelectedItems[0].Text;TreeNode existNode = nodes.SingleOrDefault<TreeNode>(s => s.Text == selectItem);tv_Dirs.SelectedNode = existNode;}else{string filePath = tv_Dirs.SelectedNode.FullPath +"\\"+ lv_DirsAndFiles.SelectedItems[0].Text;System.Diagnostics.Process.Start(filePath);}}}//返回上一层private void BackToLastLayer(){TreeNode parent = tv_Dirs.SelectedNode.Parent;if (parent != null){tv_Dirs.SelectedNode = parent;}}//删除操作private void Delete(){int count = lv_DirsAndFiles.SelectedItems.Count;if (count> 0){for (int i = 0; i < count; i++){if (lv_DirsAndFiles.SelectedItems[0].ImageIndex == 1){TreeNode[] nodes = newTreeNode[tv_Dirs.SelectedNode.Nodes.Count];tv_Dirs.SelectedNode.Nodes.CopyTo(nodes, 0);string selectItem =lv_DirsAndFiles.SelectedItems[0].Text;TreeNode existNode =nodes.SingleOrDefault<TreeNode>(s => s.Text == selectItem);Directory.Delete(existNode.FullPath,true);lv_DirsAndFiles.Items.Remove(lv_DirsAndFiles.SelectedItems[0]);tv_Dirs.SelectedNode.Nodes.Remove(existNode);}else{File.Delete(tv_Dirs.SelectedNode.FullPath + "\\" + lv_DirsAndFiles.SelectedItems[0].Text);lv_DirsAndFiles.Items.Remove(lv_DirsAndFiles.SelectedItems[0]);}}}}//private void NewFile(){ListViewItem lvi = new ListViewItem();lvi.Text = "新建文本文件" + newfileCount.ToString()+".txt";lvi.ImageIndex = 2;lvi.Selected=true;lv_DirsAndFiles.Items.Add(lvi);lv_belEdit = true;lv_DirsAndFiles.SelectedItems[0].BeginEdit();newfileCount++;}private void NewPath(){ListViewItem lvi = new ListViewItem();lvi.Text = "新建文件夹" + newfileCount.ToString();lvi.ImageIndex = 1;lvi.Selected = true;lv_DirsAndFiles.Items.Add(lvi);lv_belEdit = true;lv_DirsAndFiles.SelectedItems[0].BeginEdit();newFolderCount++;}private void Rename(string source,string dest){if (File.Exists(source )== false){Directory.Move(source,dest );TreeNode[] nodes = newTreeNode[tv_Dirs.SelectedNode.Nodes.Count];tv_Dirs.SelectedNode.Nodes.CopyTo(nodes, 0);string oldItem = source.Substring(stIndexOf('\\') + 1, source.Length - stIndexOf('\\')-1);string newItem = dest.Substring(stIndexOf('\\') + 1, dest.Length - stIndexOf('\\') - 1);TreeNode existNode = nodes.SingleOrDefault<TreeNode>(s => s.Text ==oldItem);existNode.Text = newItem;}else{File.Move(source,dest);}}#endregionprivate void lv_DirsAndFiles_AfterLabelEdit(object sender, LabelEditEventArgs e){string name =bel ;if (string.IsNullOrEmpty(name)){name = lv_DirsAndFiles.SelectedItems[0].Text;}if (operatinFlag == 0){File.Create(tv_Dirs.SelectedNode.FullPath + "\\" + name );}else if (operatinFlag == 1){Directory.CreateDirectory(tv_Dirs.SelectedNode.FullPath + "\\" + name);tv_Dirs.SelectedNode.Nodes.Add(new TreeNode(name, 1, 1));}else if(operatinFlag==2){Rename(tv_Dirs.SelectedNode.FullPath + "\\" +lv_DirsAndFiles.SelectedItems[0].Text,tv_Dirs.SelectedNode.FullPath + "\\" +name);}}}}留言板管理员登录登录后可进行留言回复操作查看留言任何人可查看所有留言客户留言客户可查看所有留言信息(包括管理员回复)回复留言管理员查看客户留言信息并可回复其留言逻辑结构1,不注册可以查看,不能回复和留言2,点击回复跳到回复框(最下面,和发表框共享),登陆之后才能回复和发帖留言(发帖验证用户名和密码,可注册)3,发帖内容先发到数据库,再通过数据绑定显示到repeater中的表格的列里面.*4,点击留言,验证是否登陆,未登陆则聚焦到登陆框;上面(页眉以上)已登陆,则显示登录用户名,同时下面(留言框下)的登陆框隐藏.5,标题和内容都显示在一列里面,标题加粗显示Jquery赋值("<%=txtName.ClientID%>");绑定<%#(”txtName“)%>;写代码(asp方式)<% %>;lbtnDel_ClickLinkButton lbtn=sender as LinkButton;int id=Conver.ToInt32(mandArgument);Message ms=dct.Message.Where(w=>w.MessageID==id).First();dct.Message.DeleteOnSubmit(ms);dct.SubmitChanges();登陆Session["user"]=name;Response.Redirect("Default.aspx");通过获取Session判定显示还是隐藏.page_load里面(ispostback外面):(if(Session["user"]!=null){//注册脚本过去Page.ClientScript.RegisterStartupScript(this.GetType(),"sd","ShowCommand('block' )",true);}else{Page.ClientScript.RegisterStartupScript(this.GetType(),"sdwd","ShowCommand(' none')",true);})前台JS:function ShowCommand(obj){var tab=$("label #lblCommand").css("display",obj);}数据库create table message(MessageID int identity(1,1) primary key,UserName varchar(50),PostTime datetime,Messages varchar(500),IsReplied bit,Reply varchar(500))。
用DELPHI编写WINDOWS服务程序
会把所有的请求委托给该 TServiceThread 成员对象处理,该对象以默认的方式处理所有的请求。 TService. ServiceExecute 是 TService 的主体内容。一个服务要正常运行,除了需要处理它要关注的目标(比如监听某个端口、执行某个 任务等)外,还要响应外部命令/请求:比如终止、暂停、恢复该服务。因此可以考虑创建一个专门的线程来完成该任务,而在 ServiceExecute 中处理外面命令/请求inated do begin ServiceThread.ProcessRequests(False); end; 当然,也可以在 OnExecute 中处理某些任务,如监听某个端口,但是这常常会导致该 Service 不能及时响应 Stop/Pause 等请求。当 OnExecute 执行完了,该服务实际上就完成了任务要结束了(terminate)。
MyPHSThread := TPHSSendThread.Create(); MyPHSThread.FreeOnTerminate:=True;
MyPHSThread.Priority:= tpLower ;
end;
在 OnStop 事件内,我们应该停止线程,并释放打开的资源,需要注意的是当你停止线程时,一般用 Terminate 方法,在线程内用 Terminated 属性来判断 是否需要结束线程,而由于是线程,和主进程是时间运行的,有可能你刚好在进行 Terminate 时,线程已经刚进行过 Terminated 判断,正在进行比较费时 的处理工作,而此时主进程立即执行 Terminate 后就进行释放资源的工作时,会造成线程执行错误,因此应该等到线程真正的正确停止后,主进程才能进行资 源释放工作。
三、TService
记事本程序源代码汇总
记事本程序源代码汇总下面是一个简单的记事本程序的源代码:```#include <iostream>#include <fstream>#include <string>using namespace std;void showMencout << "**********************" << endl; cout << " 记事本程序 " << endl; cout << "**********************" << endl; cout << "请选择以下操作:" << endl;cout << "1. 新建记事本文件" << endl;cout << "2. 打开已有记事本文件" << endl; cout << "3. 查看记事本文件内容" << endl; cout << "4. 添加文本到记事本文件" << endl; cout << "5. 退出程序" << endl;cout << "**********************" << endl; void createFilstring filename;cout << "请输入新建记事本文件的文件名:";cin >> filename;//在当前目录创建一个新文件ofstream outFile(filename);outFile.close(;cout << "成功创建记事本文件:" << filename << endl; void openFilstring filename;cout << "请输入要打开的记事本文件的文件名:";cin >> filename;//尝试打开已存在的文件ifstream inFile(filename);if (!inFile)cout << "无法打开文件:" << filename << endl;} elsestring content;getline(inFile, content, '\0');cout << "记事本文件内容:" << endl;cout << content << endl;inFile.close(;}void viewFilstring filename;cout << "请输入要查看的记事本文件的文件名:"; cin >> filename;//尝试打开已存在的文件ifstream inFile(filename);if (!inFile)cout << "无法打开文件:" << filename << endl; } elsestring line;cout << "记事本文件内容:" << endl;while (getline(inFile, line))cout << line << endl;}inFile.close(;}void appendToFilstring filename;cout << "请输入要添加文本的记事本文件的文件名:";cin >> filename;//尝试打开已存在的文件ofstream outFile(filename, ios::app);if (!outFile)cout << "无法打开文件:" << filename << endl;} elsestring content;cout << "请输入要添加的文本内容(以#结束):" << endl; while (true)getline(cin, content);if (content == "#")break;}outFile << content << endl;}outFile.close(;cout << "成功添加文本到记事本文件:" << filename << endl; }int maiint choice;doshowMenu(;cout << "请输入您的选择:";cin >> choice;switch (choice)case 1:createFile(;break;case 2:openFile(;break;case 3:viewFile(;break;case 4:appendToFile(;break;case 5:cout << "感谢使用记事本程序,再见!" << endl;break;default:cout << "无效的选择,请重新输入!" << endl;}} while (choice != 5);return 0;```这个记事本程序通过命令行界面提供了以下操作:1.新建记事本文件:用户输入一个文件名后,在当前目录下创建一个新文件作为记事本。
Delphi高仿windows记事本源码
主要功能都已添加上并测试可用。
效果图:源码:unit Unit1Calculator;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ComCtrls;typeTForm1 = class(TForm)ColorDialog1: TColorDialog;SaveDialog1: TSaveDialog;ColorDialog2: TColorDialog;MainMenu1: TMainMenu;N1: TMenuItem;myNew: TMenuItem;mySave: TMenuItem;N3: TMenuItem;myPage: TMenuItem;myPrint: TMenuItem;myQuit: TMenuItem;myEdit: TMenuItem;myUndo: TMenuItem;N4: TMenuItem;myCut: TMenuItem;myCopy: TMenuItem;myPaste: TMenuItem;myDelete: TMenuItem;N6: TMenuItem;myFind: TMenuItem;myReplace: TMenuItem;myFormat: TMenuItem;myFont: TMenuItem;myView: TMenuItem;myStatus: TMenuItem;myHelp: TMenuItem;myHelpTopics: TMenuItem;N9: TMenuItem;myAbout: TMenuItem;OpenDialog1: TOpenDialog;FontDialog1: TFontDialog;myOpen: TMenuItem;FindDialog1: TFindDialog;ReplaceDialog1: TReplaceDialog;FontDialog2: TFontDialog;PageSetupDialog1: TPageSetupDialog;PrintDialog1: TPrintDialog;RichEdit1: TRichEdit;procedure myNewClick(Sender: TObject);procedure FormCreate(Sender: TObject);procedure myOpenClick(Sender: TObject);procedure mySaveClick(Sender: TObject);procedure myQuitClick(Sender: TObject);procedure myUndoClick(Sender: TObject);procedure myCutClick(Sender: TObject);procedure myCopyClick(Sender: TObject);procedure myPasteClick(Sender: TObject);procedure myDeleteClick(Sender: TObject);procedure myFindClick(Sender: TObject);procedure myReplaceClick(Sender: TObject);procedure myFontClick(Sender: TObject);procedure myPageClick(Sender: TObject);procedure myPrintClick(Sender: TObject);procedure myAboutClick(Sender: TObject);procedure myHelpTopicsClick(Sender: TObject);procedure FormClose(Sender: TObject; var Action: TCloseAction); private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}var fName: String;procedure TForm1.myNewClick(Sender: TObject);var msg : integer;beginif (richEdit1.Modified) thenbeginmsg := Application.MessageBox('文件已被修改,是否保存?', 'Delphi记事本', mb_YesNoCancel);case msg ofidYes: beginmySaveClick(Sender);richEdit1.Clear;fName := '文档1';Caption := fName + '--Delphi记事本';end;idNo: beginrichEdit1.Clear;fName := '文档1';Caption := fName + '--Delphi记事本';end;idCancel: ;end;endelse beginrichEdit1.Clear;fName := '文档1';Caption := fName + '--Delphi记事本';end;end;procedure TForm1.FormCreate(Sender: TObject);beginfName := '文档1';richEdit1.Clear;Caption := fName + '--Delphi记事本';end;procedure TForm1.myOpenClick(Sender: TObject);var msg : integer;beginif (richEdit1.Modified) thenbeginmsg := Application.MessageBox('文件已被修改,是否保存?', 'Delphi记事本', mb_YesNoCancel);case msg ofidYes: beginmySaveClick(Sender);end;idNo: if (openDialog1.Execute) thenbeginfName := openDialog1.FileName;richEdit1.Lines.LoadFromFile(fName);form1.Caption := fName + 'Delphi记事本';end;idCancel: ;end;endelse if (openDialog1.Execute) thenbeginfName := openDialog1.FileName;richEdit1.Lines.LoadFromFile(fName);form1.Caption := fName + 'Delphi记事本';end;end;procedure TForm1.mySaveClick(Sender: TObject);beginif (fName <> '文档1') thenbeginrichEdit1.Lines.SaveToFile(fName);endelse beginsaveDialog1.FileName := fName;if (saveDialog1.Execute) thenbeginfName := saveDialog1.FileName;richEdit1.Lines.SaveToFile(fName);form1.Caption := fName;end;end;richEdit1.Modified := false;end;procedure TForm1.myQuitClick(Sender: TObject);beginif (richEdit1.Modified) then mySaveClick(Sender); Application.Terminate;end;procedure TForm1.myUndoClick(Sender: TObject);beginrichEdit1.Undo;end;procedure TForm1.myCutClick(Sender: TObject);beginrichEdit1.CutToClipboard;end;procedure TForm1.myCopyClick(Sender: TObject);beginrichEdit1.CopyToClipboard;end;procedure TForm1.myPasteClick(Sender: TObject);beginrichEdit1.PasteFromClipboard;end;procedure TForm1.myDeleteClick(Sender: TObject);beginrichEdit1.ClearSelection;end;procedure TForm1.myFindClick(Sender: TObject);beginfindDialog1.Execute;end;procedure TForm1.myReplaceClick(Sender: TObject);beginreplaceDialog1.Execute;end;procedure TForm1.myFontClick(Sender: TObject);beginfontDialog1.Font := richEdit1.Font; //初始化字体对话框if (fontDialog1.Execute) then richEdit1.SelAttributes.Assign(fontDialog1.Font); end;procedure TForm1.myPageClick(Sender: TObject);beginpageSetupDialog1.Execute;end;procedure TForm1.myPrintClick(Sender: TObject);beginif (printDialog1.Execute) thenbeginrichEdit1.Print(fName);end;end;procedure TForm1.myAboutClick(Sender: TObject);beginShowMessage('Delphi记事本1.0' + #13 + ' 记念于12.5.14');end;procedure TForm1.myHelpTopicsClick(Sender: TObject);beginmyAboutClick(Sender);end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); beginmyQuitClick(Sender);end;end.。
用delphi编写的记事本代码.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, ComCtrls, ExtCtrls, ToolWin, ImgList; type TForm1 = class(TForm MainMenu1: TMainMenu; RichEdit1: TRichEdit; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; FontDialog1: TFontDialog; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; 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; PopupMenu1: TPopupMenu; FindDialog1: TFindDialog; N21: TMenuItem; PrintDialog1: TPrintDialog; N22: TMenuItem; N23: TMenuItem; N24: TMenuItem; N25: TMenuItem; N26: TMenuItem; N27: TMenuItem; N28: TMenuItem; N31: TMenuItem; N32: TMenuItem; S1: TMenuItem; Timer1: TTimer; StatusBar2: TStatusBar; ToolBar1: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; ToolButton3: TToolButton; ToolButton4: TToolButton; ToolButton5: TToolButton; ToolButton6: TToolButton; ToolButton7: TToolButton; ToolButton8: TToolButton; ToolButton9: TToolButton; ToolButton10: TToolButton; ToolButton11: TToolButton; ToolButton12: TToolButton; ToolButton13: TToolButton; ImageList1: TImageList; procedureN2Click(Sender: TObject; procedure N3Click(Sender: TObject; procedureN7Click(Sender: TObject; procedure N8Click(Sender: TObject; procedureN9Click(Sender: TObject; procedure N14Click(Sender: TObject; procedureN21Click(Sender: TObject; procedure N16Click(Sender: TObject; procedureN17Click(Sender: TObject; procedure N18Click(Sender: TObject; procedureN12Click(Sender: TObject; procedure N20Click(Sender: TObject; procedureN6Click(Sender: TObject; procedure S1Click(Sender: TObject; procedureFindDialog1Find(Sender: TObject; procedure Timer1Timer(Sender: TObject; procedure N24Click(Sender: TObject; procedure N25Click(Sender: TObject; procedureN26Click(Sender: TObject; procedure N27Click(Sender: TObject; procedureN28Click(Sender: TObject; procedure RichEdit1MouseMove(Sender: TObject; Shift:TShiftState; X, Y: Integer; procedure RichEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState; procedure RichEdit1Enter(Sender: TObject; private { Private declarations } public { Public declarations } end; var Form1: TForm1; filename: string; temp:integer; implementation {$R *.dfm} procedure TForm1.N2Click(Sender: TObject; begin if opendialog1.Execute then begin Form1.Caption:=ExtractFileName(OpenDialog1.FileName;richedit1.lines.LoadFromFile(opendialog1.FileName; end end; procedureTForm1.N3Click(Sender: TObject; begin if filename='' then begin if savedialog1.Execute then begin richedit1.Lines.SaveToFile(savedialog1.FileName;filename:=savedialog1.filename; end end elserichedit1.Lines.SaveToFile(savedialog1.FileName; end; procedureTForm1.N7Click(Sender: TObject; begin fontdialog1.Execute;richedit1.SelAttributes.Assign(fontdialog1.Font; end; procedure TForm1.N8Click(Sender: TObject; begin if RichEdit1.Modified then begin temp:=MessageDlg('内容发生改变,是否要保存',mtwarning,mbyesnocancel,0; if temp=6 then begin Form1.N3Click(Sender ; RichEdit1.Lines.Clear; end; if temp=7 then RichEdit1.Lines.Clear; end elseRichEdit1.Lines.Clear; end; procedure TForm1.N9Click(Sender: TObject; begin with savedialog1 do if execute then begin richedit1.Lines.SaveToFile (filename;opendialog1.FileName := filename; end; end; procedure TForm1.N14Click(Sender: TObject; begin richedit1.Perform(EM_UNDO,0,0; end; procedureTForm1.N21Click(Sender: TObject; begin richedit1.SelectAll; end; procedureTForm1.N16Click(Sender: TObject; begin richedit1.cuttoclipboard; end; procedure TForm1.N17Click(Sender: TObject; begin richedit1.copyToClipboard; end; procedure TForm1.N18Click(Sender: TObject; begin richedit1.PasteFromClipboard; end; procedure TForm1.N12Click(Sender: TObject; begin PrintDialog1.Execute; end; procedureTForm1.N20Click(Sender: TObject; begin finddialog1.Execute; end; procedureTForm1.N6Click(Sender: TObject; begin if N6.Checked then begin N6.Checked:=false; RichEdit1.WordWrap:=False; end else begin n6.Checked:=True;RichEdit1.WordWrap:=True; end end; procedure TForm1.S1Click(Sender: TObject; begin if s1.Checked then begin s1.Checked:=false; statusbar2.visible:=False; end else begin s1.Checked:=True; statusbar2.visible:=True; end end; procedureTForm1.FindDialog1Find(Sender: TObject; Var findat:longint; startpos,toend:integer; begin with richedit1 do begin if sellength<>0 then startpos:=selstart+sellength else startpos:=0; toend:=length(text-startpos;findat:=findtext(FindDialog1.FindText,startpos,toend,[stMatchCase]; if findat<>-1 then begin setfocus ; SelStart:=findat; SelLength:=Length(FindDialog1.FindText end; end; end; procedure TForm1.Timer1Timer(Sender: TObject; beginstatusbar2.Panels[1].Text:=timetostr(time(; end; procedure TForm1.N24Click(Sender: TObject; begin richedit1.Perform(EM_UNDO,0,0; end; procedureTForm1.N25Click(Sender: TObject; begin richedit1.cuttoclipboard; end; procedure TForm1.N26Click(Sender: TObject; begin richedit1.copyToClipboard; end; procedure TForm1.N27Click(Sender: TObject; begin richedit1.PasteFromClipboard; end; procedure TForm1.N28Click(Sender: TObject; begin richedit1.SelectAll; end; procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer; begin StatusBar2.Panels[0].Text:=IntToStr(RichEdit1.CaretPos.Y+1+'行'+inttostr(RichEdit1.CaretPos.X+1+'列' end; procedureTForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState; begin if Key=13 then StatusBar2.Panels[0].Text:=IntToStr(RichEdit1.CaretPos.Y+2+'行'+'1列' else StatusBar2.Panels[0].Text:=IntToStr(RichEdit1.CaretPos.Y+1+ '行'+inttostr(RichEdit1.CaretPos.X+2+'列' end; procedure TForm1.RichEdit1Enter(Sender: TObject; begin StatusBar2.Panels[0].Text:=IntToStr(RichEdit1.CaretPos.Y+1+'行'+inttostr(RichEdit1.CaretPos.X+1+'列' end; end.。
delphi中记事本功能实现
应用公共对话框、菜单组件、工具栏组件、其他可视化组件,完成菜单设计,工具栏设计,完成学生基本信息管理系统,实现学生信息的建立、增加、修改、删除、浏览、查询、保存等功能。
要求:使用记录类型处理学生信息,使用记录型文件保存学生信息(文件扩展名.dat)。
参考界面unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Menus, FileCtrl, Mask, jpeg;typeTForm1 = class(TForm)MainMenu1: TMainMenu;N1: TMenuItem;Y1: TMenuItem;Z1: TMenuItem;X1: TMenuItem;Y2: TMenuItem;Z2: TMenuItem;V1: TMenuItem;W1: TMenuItem;X01: TMenuItem;Y3: TMenuItem;Z3: TMenuItem;PageControl1: TPageControl;TabSheet1: TTabSheet;TabSheet2: TTabSheet;GroupBox1: TGroupBox;Panel1: TPanel;Label1: TLabel;Label2: TLabel;Label3: TLabel;Label4: TLabel;Label5: TLabel; RadioButton1: TRadioButton; RadioButton2: TRadioButton; Edit1: TEdit;GroupBox2: TGroupBox; RadioButton3: TRadioButton; RadioButton4: TRadioButton; GroupBox3: TGroupBox; CheckBox1: TCheckBox; CheckBox2: TCheckBox; CheckBox3: TCheckBox; CheckBox4: TCheckBox; GroupBox4: TGroupBox; Button1: TButton;Button2: TButton;Button3: TButton;Button4: TButton;Button5: TButton; GroupBox5: TGroupBox; Button6: TButton;Button7: TButton;Button8: TButton;Button9: TButton;Button10: TButton; GroupBox6: TGroupBox; GroupBox7: TGroupBox; GroupBox8: TGroupBox; Label6: TLabel;Label7: TLabel;Edit4: TEdit;Button11: TButton;Button12: TButton; MaskEdit1: TMaskEdit; MaskEdit2: TMaskEdit; Shape1: TShape;Label8: TLabel; ComboBox1: TComboBox; ListBox1: TListBox;Image1: TImage;Edit2: TEdit;procedure FormCreate(Sender: TObject);procedure ListBox1Click(Sender: TObject);procedure Button1Click(Sender: TObject);procedure Button2Click(Sender: TObject);procedure Button3Click(Sender: TObject);procedure Button4Click(Sender: TObject);procedure Button5Click(Sender: TObject);procedure Button6Click(Sender: TObject);procedure Button7Click(Sender: TObject);procedure Button8Click(Sender: TObject);procedure Button9Click(Sender: TObject);procedure Button10Click(Sender: TObject);procedure Button11Click(Sender: TObject);procedure X1Click(Sender: TObject);procedure Y2Click(Sender: TObject);procedure Z2Click(Sender: TObject);procedure V1Click(Sender: TObject);procedure W1Click(Sender: TObject);procedure X01Click(Sender: TObject);procedure Y3Click(Sender: TObject);procedure Z3Click(Sender: TObject);procedure Button12Click(Sender: TObject); private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;typestudent=recordno:string[4];xm,sr,dh,mz:string[20];xb:string[2];ah:string[30];end;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);vart:student;f:file of student;beginassignfile(f,'student.dat');if fileexists('student.dat') thenreset(f)elserewrite(f);while not eof(f) dobeginread(f,t);listbox1.Items.add(t.no+' '+t.xm+' '+t.xb+' '+t.mz+' '+t.sr+' '+t.dh+' '+t.ah); end;closefile(f);button2.Enabled:=false;button3.Enabled:=false;button4.Enabled:=false;end;procedure TForm1.ListBox1Click(Sender: TObject); //是否选中记录beginif listbox1.ItemIndex>-1 thenbeginbutton2.Enabled:=true;button3.Enabled:=true;button4.Enabled:=true;endelsebeginbutton2.Enabled:=false;button3.Enabled:=false;button4.Enabled:=false;end;end;procedure TForm1.Button1Click(Sender: TObject); //添加记录var t:student;f:file of student;size:integer;s:string;begins:='';t.no:=edit2.Text;t.xm:=edit1.Text ;t.sr:=maskedit1.Text ;t.dh:=maskedit2.Text ;if radiobutton1.Checked then t.xb:='男' else t.xb:='女';if radiobutton3.Checked then t.mz:='汉族' else t.mz:='少数民族';if checkbox1.Checked then s:=s+'钓鱼、';if checkbox2.Checked then s:=s+'读书、';if checkbox3.Checked then s:=s+'下棋、';if checkbox4.Checked then s:=s+'打球、';t.ah:=copy(s,0,length(s)-2);assignfile(f,'student.dat');reset(f);size:=filesize(f);seek(f,size);write(f,t);listbox1.Items.Clear ;seek(f,0);while not eof(f) dobeginread(f,t);listbox1.Items.add(t.no+' '+t.xm+' '+t.xb+' '+t.mz+' '+t.sr+' '+t.dh+' '+t.ah); end;closefile(f);edit1.text:='';edit2.text:='';maskedit1.Text:='';maskedit2.Text:='';radiobutton1.Checked:=false;radiobutton2.Checked:=false;radiobutton3.Checked:=false;radiobutton4.Checked:=false;checkbox1.Checked:=false;checkbox2.Checked:=false;checkbox3.Checked:=false;checkbox4.Checked:=false;end;procedure TForm1.Button2Click(Sender: TObject); //删除记录var pos:integer;t:student;f:file of student;beginpos:=listbox1.ItemIndex;assignfile(f,'student.dat');reset(f);seek(f,pos+1);while not eof(f) dobeginread(f,t);seek(f,pos);pos:=pos+1;write(f,t);seek(f,pos+1);end;seek(f,pos);truncate(f);seek(f,0);listbox1.Items.Clear;while not eof(f) dobeginread(f,t);listbox1.Items.add(t.no+' '+t.xm+' '+t.xb+' '+t.mz+' '+t.sr+' '+t.dh+' '+t.ah); end;closefile(f);end;procedure TForm1.Button3Click(Sender: TObject); //修改记录var t:student;f:file of student;pos:integer;s:string;beginpos:=listbox1.ItemIndex;assignfile(f,'student.dat');reset(f);seek(f,pos);read(f,t);edit2.Text:=t.no;edit1.Text:=t.xm;maskedit1.Text:=t.sr;maskedit2.Text:=t.dh;s:=t.ah;if t.xb='男' thenradiobutton1.Checked:=trueelseradiobutton2.Checked:=true;if t.mz='汉族' thenradiobutton3.Checked:=trueelseradiobutton4.Checked:=true;if(copy(s,0,4)='钓鱼') thencheckbox1.Checked:=true;if( copy(s,0,4)='读书') or (copy(s,7,4)='读书' ) thencheckbox2.Checked:=true;if( copy(s,0,4)='下棋') or (copy(s,7,4)='下棋') or (copy(s,13,4)='下棋') thencheckbox3.Checked:=true;if( copy(s,0,4)='打球') or (copy(s,7,4)='打球') or (copy(s,13,4)='打球') or (copy(s,19,4)='打球') thencheckbox3.Checked:=true;closefile(f);end;procedure TForm1.Button4Click(Sender: TObject); //保存修改var t:student;f:file of student;pos:integer;s:string;beginpos:=listBox1.ItemIndex;assignfile(f,'student.dat');reset(f);seek(f,pos-1);read(f,t);s:='';t.no:=edit2.Text;t.xm:=edit1.Text;t.sr:=maskedit1.Text;t.dh:=maskedit2.Text;if radiobutton1.Checked then t.xb:='男' else t.xb:='女';if radiobutton3.Checked then t.mz:='汉族' else t.mz:='少数民族';if checkbox1.Checked then s:=s+'钓鱼、';if checkbox2.Checked then s:=s+'读书、';if checkbox3.Checked then s:=s+'下棋、';if checkbox4.Checked then s:=s+'打球、';t.ah:=copy(s,0,length(s)-2);write(f,t);listbox1.Items.Clear ;seek(f,0);while not eof(f) dobeginread(f,t);listbox1.Items.add(t.no+' '+t.xm+' '+t.xb+' '+t.mz+' '+t.sr+' '+t.dh+' '+t.ah); end;closefile(f);end;procedure TForm1.Button5Click(Sender: TObject); //显示所有var t:student;f:file of student;beginassignfile(f,'student.dat');if fileexists('student.dat') thenreset(f)elserewrite(f);listbox1.Items.Clear;seek(f,0);while not eof(f) dobeginread(f,t);listbox1.Items.add(t.no+' '+t.xm+' '+t.xb+' '+t.mz+' '+t.sr+' '+t.dh+' '+t.ah); end;closefile(f);tabsheet1.Show;end;procedure TForm1.Button6Click(Sender: TObject); //第一条var t:student;f:file of student;s:string;beginassignfile(f,'student.dat');reset(f);seek(f,0);read(f,t);edit2.Text:=t.no;edit1.Text:=t.xm;maskedit1.Text:=t.sr;maskedit2.Text:=t.dh;if t.xb='男' thenradiobutton1.Checked:=trueelseradiobutton2.Checked:=true;if t.mz='汉族' thenradiobutton3.Checked:=trueelseradiobutton4.Checked:=true;if(copy(s,0,4)='钓鱼') thencheckbox1.Checked:=true;if( copy(s,0,4)='读书') or (copy(s,7,4)='读书' ) thencheckbox2.Checked:=true;if( copy(s,0,4)='下棋') or (copy(s,7,4)='下棋') or (copy(s,13,4)='下棋') thencheckbox3.Checked:=true;if( copy(s,0,4)='打球') or (copy(s,7,4)='打球') or (copy(s,13,4)='打球') or (copy(s,19,4)='打球') thencheckbox3.Checked:=true;closefile(f);end;procedure TForm1.Button7Click(Sender: TObject); //上一条var t:student;f:file of student;pos:integer;s:string;beginpos:=listbox1.ItemIndex;assignfile(f,'student.dat');reset(f);//seek(f,pos-1);//read(f,t);if pos-1=-1 thenshowmessage('已经是第一条记录,无法再查找上一条记录!')elsebeginseek(f,pos-1);read(f,t);edit2.Text:=t.no;edit1.Text:=t.xm;maskedit1.Text:=t.sr;maskedit2.Text:=t.dh;if t.xb='男' thenradiobutton1.Checked:=trueelseradiobutton2.Checked:=true;if t.mz='汉族' thenradiobutton3.Checked:=trueelseradiobutton4.Checked:=true;if(copy(s,0,4)='钓鱼') thencheckbox1.Checked:=true;if( copy(s,0,4)='读书') or (copy(s,7,4)='读书' ) thencheckbox2.Checked:=true;if( copy(s,0,4)='下棋') or (copy(s,7,4)='下棋') or (copy(s,13,4)='下棋') thencheckbox3.Checked:=true;if( copy(s,0,4)='打球') or (copy(s,7,4)='打球') or (copy(s,13,4)='打球') or (copy(s,19,4)='打球') thencheckbox3.Checked:=true;end;closefile(f);end;procedure TForm1.Button8Click(Sender: TObject); //下一条var t:student;f:file of student;pos:integer;s:string;beginpos:=listbox1.ItemIndex;assignfile(f,'student.dat');reset(f);seek(f,pos+1);read(f,t);if pos+1=filesize(f) thenshowmessage('已经是最后一条记录,无法再查找下一条记录!')elsebeginseek(f,pos+1);read(f,t);edit2.Text:=t.no;edit1.Text:=t.xm;maskedit1.Text:=t.sr;maskedit2.Text:=t.dh;if t.xb='男' thenradiobutton1.Checked:=trueelseradiobutton2.Checked:=true;if t.mz='汉族' thenradiobutton3.Checked:=trueelseradiobutton4.Checked:=true;if(copy(s,0,4)='钓鱼') thencheckbox1.Checked:=true;if( copy(s,0,4)='读书') or (copy(s,7,4)='读书' ) thencheckbox2.Checked:=true;if( copy(s,0,4)='下棋') or (copy(s,7,4)='下棋') or (copy(s,13,4)='下棋') thencheckbox3.Checked:=true;if( copy(s,0,4)='打球') or (copy(s,7,4)='打球') or (copy(s,13,4)='打球') or (copy(s,19,4)='打球') thencheckbox3.Checked:=true;end;closefile(f);end;procedure TForm1.Button9Click(Sender: TObject); //最后一条var t:student;f:file of student;size:integer;s:string;beginassignfile(f,'student.dat');reset(f);size:=filesize(f);seek(f,size-1);read(f,t);edit2.Text:=t.no;edit1.Text:=t.xm;maskedit1.Text:=t.sr;maskedit2.Text:=t.dh;if t.xb='男' thenradiobutton1.Checked:=trueelseradiobutton2.Checked:=true;if t.mz='汉族' thenradiobutton3.Checked:=trueelseradiobutton4.Checked:=true;if(copy(s,0,4)='钓鱼') thencheckbox1.Checked:=true;if( copy(s,0,4)='读书') or (copy(s,7,4)='读书' ) thencheckbox2.Checked:=true;if( copy(s,0,4)='下棋') or (copy(s,7,4)='下棋') or (copy(s,13,4)='下棋') thencheckbox3.Checked:=true;if( copy(s,0,4)='打球') or (copy(s,7,4)='打球') or (copy(s,13,4)='打球') or (copy(s,19,4)='打球') thencheckbox3.Checked:=true;closefile(f);end;procedure TForm1.Button10Click(Sender: TObject); //退出系统beginform1.Close;end;procedure TForm1.Button11Click(Sender: TObject); //查询var t:student;f:file of student;i,j,pos:integer;begini:=0;j:=listbox1.Items.Count;pos:=0;assignfile(f,'student.dat');reset(f);listbox1.Items.Clear;while not eof(f) dobeginseek(f,pos);read(f,t);if ((edit4.text=t.no)or(edit4.text=t.xm)or(edit4.Text=t.mz)or(edit4.Text=t.xb)) then beginlistbox1.Items.add(t.no+' '+t.xm+' '+t.xb+' '+t.mz+' '+t.sr+' '+t.dh+' '+t.ah); i:=i+1;end;pos:=pos+1;end;closefile(f);label8.Caption:='共有记录条数'+#13+inttostr(j)+#13+'查询到记录'+#13+inttostr(i)+'条'; end;procedure TForm1.Button12Click(Sender: TObject); //显示所有beginButton5.Click;end;procedure TForm1.X1Click(Sender: TObject); //记录编辑(主菜单)begintabsheet2.Show;end;procedure TForm1.Y2Click(Sender: TObject); //记录查询(主菜单)begintabsheet1.Show;end;procedure TForm1.Z2Click(Sender: TObject); //退出系统(主菜单)beginform1.Close;end;procedure TForm1.V1Click(Sender: TObject); //添加记录(主菜单)begintabsheet2.Show;Button1.Click;end;procedure TForm1.W1Click(Sender: TObject); //删除记录beginButton2.Click;end;procedure TForm1.X01Click(Sender: TObject); //修改记录(主菜单)begintabsheet2.Show;Button3.Click;end;procedure TForm1.Y3Click(Sender: TObject); //保存记录(主菜单)beginButton4.Click;end;procedure TForm1.Z3Click(Sender: TObject);beginButton12.Click;end;end.。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
主要功能都已添加上并测试可用。
效果图:源码:unit Unit1Calculator;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,Menus,StdCtrls,ComCtrls;typeTForm1=class(TForm)ColorDialog1:TColorDialog;SaveDialog1:TSaveDialog;ColorDialog2:TColorDialog;MainMenu1:TMainMenu;N1:TMenuItem;myNew:TMenuItem;mySave:TMenuItem;N3:TMenuItem;myPage:TMenuItem;myPrint:TMenuItem;myQuit:TMenuItem;myEdit:TMenuItem;myUndo:TMenuItem;N4:TMenuItem;myCut:TMenuItem;myCopy:TMenuItem;myPaste:TMenuItem;myDelete:TMenuItem;N6:TMenuItem;myFind:TMenuItem;myReplace:TMenuItem;myFormat:TMenuItem;myFont:TMenuItem;myView:TMenuItem;myStatus:TMenuItem;myHelp:TMenuItem;myHelpTopics:TMenuItem;N9:TMenuItem;myAbout:TMenuItem;OpenDialog1:TOpenDialog;FontDialog1:TFontDialog;myOpen:TMenuItem;FindDialog1:TFindDialog;ReplaceDialog1:TReplaceDialog;FontDialog2:TFontDialog;PageSetupDialog1:TPageSetupDialog;PrintDialog1:TPrintDialog;RichEdit1:TRichEdit;procedure myNewClick(Sender:TObject);procedure FormCreate(Sender:TObject);procedure myOpenClick(Sender:TObject);procedure mySaveClick(Sender:TObject);procedure myQuitClick(Sender:TObject);procedure myUndoClick(Sender:TObject);procedure myCutClick(Sender:TObject);procedure myCopyClick(Sender:TObject);procedure myPasteClick(Sender:TObject);procedure myDeleteClick(Sender:TObject);procedure myFindClick(Sender:TObject);procedure myReplaceClick(Sender:TObject);procedure myFontClick(Sender:TObject);procedure myPageClick(Sender:TObject);procedure myPrintClick(Sender:TObject);procedure myAboutClick(Sender:TObject);procedure myHelpTopicsClick(Sender:TObject);procedure FormClose(Sender:TObject;var Action:TCloseAction); private{Private declarations}public{Public declarations}end;varForm1:TForm1;implementation{$R*.dfm}var fName:String;procedure TForm1.myNewClick(Sender:TObject);var msg:integer;beginif(richEdit1.Modified)thenbeginmsg:=Application.MessageBox('文件已被修改,是否保存?', 'Delphi记事本',mb_YesNoCancel);case msg ofidYes:beginmySaveClick(Sender);richEdit1.Clear;fName:='文档1';Caption:=fName+'--Delphi记事本';end;idNo:beginrichEdit1.Clear;fName:='文档1';Caption:=fName+'--Delphi记事本';end;idCancel:;end;endelse beginrichEdit1.Clear;fName:='文档1';Caption:=fName+'--Delphi记事本';end;end;procedure TForm1.FormCreate(Sender:TObject);beginfName:='文档1';richEdit1.Clear;Caption:=fName+'--Delphi记事本';end;procedure TForm1.myOpenClick(Sender:TObject);var msg:integer;beginif(richEdit1.Modified)thenbeginmsg:=Application.MessageBox('文件已被修改,是否保存?', 'Delphi记事本',mb_YesNoCancel);case msg ofidYes:beginmySaveClick(Sender);end;idNo:if(openDialog1.Execute)thenbeginfName:=openDialog1.FileName;richEdit1.Lines.LoadFromFile(fName);form1.Caption:=fName+'Delphi记事本';end;idCancel:;end;endelse if(openDialog1.Execute)thenbeginfName:=openDialog1.FileName;richEdit1.Lines.LoadFromFile(fName);form1.Caption:=fName+'Delphi记事本';end;end;procedure TForm1.mySaveClick(Sender:TObject);beginif(fName<>'文档1')thenbeginrichEdit1.Lines.SaveToFile(fName);endelse beginsaveDialog1.FileName:=fName;if(saveDialog1.Execute)thenbeginfName:=saveDialog1.FileName;richEdit1.Lines.SaveToFile(fName);form1.Caption:=fName;end;end;richEdit1.Modified:=false;end;procedure TForm1.myQuitClick(Sender:TObject);beginif(richEdit1.Modified)then mySaveClick(Sender); Application.Terminate;end;procedure TForm1.myUndoClick(Sender:TObject); beginrichEdit1.Undo;end;procedure TForm1.myCutClick(Sender:TObject);beginrichEdit1.CutToClipboard;end;procedure TForm1.myCopyClick(Sender:TObject);beginrichEdit1.CopyToClipboard;end;procedure TForm1.myPasteClick(Sender:TObject);beginrichEdit1.PasteFromClipboard;end;procedure TForm1.myDeleteClick(Sender:TObject);beginrichEdit1.ClearSelection;end;procedure TForm1.myFindClick(Sender:TObject);beginfindDialog1.Execute;end;procedure TForm1.myReplaceClick(Sender:TObject);beginreplaceDialog1.Execute;end;procedure TForm1.myFontClick(Sender:TObject);beginfontDialog1.Font:=richEdit1.Font;//初始化字体对话框if(fontDialog1.Execute)then richEdit1.SelAttributes.Assign(fontDialog1.Font); end;procedure TForm1.myPageClick(Sender:TObject);beginpageSetupDialog1.Execute;end;procedure TForm1.myPrintClick(Sender:TObject);beginif(printDialog1.Execute)thenbeginrichEdit1.Print(fName);end;end;procedure TForm1.myAboutClick(Sender:TObject);beginShowMessage('Delphi记事本1.0'+#13+'记念于12.5.14');end;procedure TForm1.myHelpTopicsClick(Sender:TObject);beginmyAboutClick(Sender);end;procedure TForm1.FormClose(Sender:TObject;var Action:TCloseAction); beginmyQuitClick(Sender);end;end.Delphi记事本程序源码及exe下载地址:/user/tp7309。