?? note.pas
字號:
unit note;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus,childform, ComCtrls, ToolWin, ImgList, StdCtrls,inifiles;
type
TMainForm = class(TForm)
MainMenu1: TMainMenu;
File1: TMenuItem;
Exit: TMenuItem;
N3: TMenuItem;
Print: TMenuItem;
N4: TMenuItem;
Save: TMenuItem;
Open: TMenuItem;
New: TMenuItem;
Window: TMenuItem;
Show1: TMenuItem;
N8: TMenuItem;
Tile1: TMenuItem;
Help: TMenuItem;
About1: TMenuItem;
Close: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ToolBar1: TToolBar;
tb_new: TToolButton;
tb_open: TToolButton;
tb_save: TToolButton;
ToolButton4: TToolButton;
tb_undo: TToolButton;
tb_cut: TToolButton;
tb_copy: TToolButton;
ImageList1: TImageList;
ToolButton8: TToolButton;
tb_print: TToolButton;
tb_preview: TToolButton;
ToolBar2: TToolBar;
ToolButton11: TToolButton;
tb_paste: TToolButton;
tb_bold: TToolButton;
tb_Italic: TToolButton;
tb_UnderLine: TToolButton;
tb_color: TToolButton;
ToolButton18: TToolButton;
tb_left: TToolButton;
tb_center: TToolButton;
tb_right: TToolButton;
StatusBar1: TStatusBar;
ComboBox1: TComboBox;
PrinterSetupDialog1: TPrinterSetupDialog;
PrintDialog1: TPrintDialog;
N1: TMenuItem;
ComboBox2: TComboBox;
ToolButton1: TToolButton;
ColorDialog1: TColorDialog;
PopupMenu1: TPopupMenu;
FontDialog1: TFontDialog;
procedure CloseClick(Sender: TObject);
procedure NewClick(Sender: TObject);
procedure OpenClick(Sender: TObject);
procedure SaveClick(Sender: TObject);
procedure Tile1Click(Sender: TObject);
procedure Cascade1Click(Sender: TObject);
procedure ArrangeAllClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure PrintSetupClick(Sender: TObject);
procedure PrintClick(Sender: TObject);
procedure MyClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure tb_boldClick(Sender: TObject);//動態菜單OnClick事件響應
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
fname:string;
achild:Tformchild;
f1,f2,f3,f4,lines:tmenuitem;
n:byte;//自動生成的子菜單個數
myinifile:Tinifile;
implementation
{$R *.dfm}
procedure TMainForm.MyClick(Sender: TObject);//動態菜單OnClick事件響應
var
i,p,l:integer;
find:boolean;
s:string;
begin
s:=TMenuItem(Sender).Caption; // 動態菜單標題
p:=pos(':',TMenuItem(Sender).Caption); //":"在菜單標題中的位置
l:=length(TMenuItem(Sender).Caption); //菜單標題長度
fname:=copy(s,p-1,l-p+2); // 取出菜單標題里面的文件路徑
i:=mdiChildCount;
find:=false;
while not find and (i>=0) do
if mdiChildren[i].Caption=fname then
begin
mdiChildren[i].Show;
find:=true;
fname:=opendialog1.FileName;
end
else
i:=i-1;
if not find then
begin
achild:=tformchild.Create(application);
achild.RichEdit1.Lines.LoadFromFile(fname);
achild.Caption:=fname;
end;
end;
procedure TMainForm.CloseClick(Sender: TObject);
begin
self.ActiveMDIChild.Close;
end;
procedure TMainForm.NewClick(Sender: TObject);
begin
achild:=tformChild.Create(application);
achild.RichEdit1.Clear;
getdir(0,fname);
if length(fname)=3 then
fname:=fname+'文檔'+inttostr(MdiChildCount)
else
fname:=fname+'\文檔'+inttostr(mdichildcount);
achild.Caption:=fname;
end;
procedure TMainForm.OpenClick(Sender: TObject);
var
i:integer;
find:boolean;
begin
if opendialog1.Execute and fileExists(opendialog1.FileName) then
begin
i:=mdiChildCount;
find:=false;
while not find and (i>=0) do
if mdiChildren[i].Caption=opendialog1.FileName then
begin
mdiChildren[i].Show;
find:=true;
fname:=opendialog1.FileName;
end
else
i:=i-1;
if not find then
begin
achild:=tformchild.Create(application);
achild.RichEdit1.Lines.LoadFromFile(opendialog1.FileName);
achild.Caption:=opendialog1.FileName;
fname:=opendialog1.FileName;
end;
end;
//動態創建菜單
try
lines:=tMenuItem.Create(self);
lines.Caption:='-';
if n=1 then
begin
file1.Insert(file1.Count-1,lines);
myinifile.WriteString('line','分割線',lines.Caption); //寫入ini文件
end;
f1:=tMenuItem.Create(self);
f1.Caption:=inttostr(n)+' '+fname;
file1.Insert(file1.Count-2,f1);
myinifile.WriteString('path'+inttostr(n),'文件路徑',f1.Caption); //寫入ini文件
f1.OnClick:=myclick;
except
f1.Free;
lines.Free;
raise;
end;
n:=n+1;
if n=5 then n:=1;
end;
procedure TMainForm.SaveClick(Sender: TObject);
var
curChild:Tformchild;
begin
curChild:=self.ActiveMDIchild as Tformchild;
if pos('文檔',fname)<>0 then
begin
if savedialog1.Execute then
begin
fname:=savedialog1.FileName;
curchild.richedit1.Lines.savetofile(fname);
curchild.Caption:=fname;
end;
end
else
begin
fname:=self.ActiveMDIChild.Caption;
curchild.richedit1.Lines.savetofile(fname);
curchild.Caption:=fname;
end;
end;
procedure TMainForm.Tile1Click(Sender: TObject);
begin
Tile;
end;
procedure TMainForm.Cascade1Click(Sender: TObject);
begin
cascade ;
end;
procedure TMainForm.ArrangeAllClick(Sender: TObject);
begin
ArrangeIcons;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
combobox1.Items:=screen.Fonts;
n:=1;
end;
procedure TMainForm.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
combobox1.Canvas.FillRect(rect);
combobox1.Canvas.Font.Name:=combobox1.Items[index];
combobox1.Canvas.Font.Size:=0;
combobox1.Canvas.TextOut(rect.Left+1,rect.Top,combobox1.Items[index])
end;
procedure TMainForm.PrintSetupClick(Sender: TObject);
begin
try
PrinterSetupDialog1.Execute
except
Application.MessageBox(Pchar('無法找到默認的打印機'+#13+#10+'請確認打印機已安裝正確。'),Pchar(Application.Title),MB_ICONEXCLAMATION);
end;
end;
procedure TMainForm.PrintClick(Sender: TObject);
begin
try
formchild.RichEdit1.Print(FName);
except
Application.MessageBox(Pchar('無法找到默認的打印機'+#13+#10+'請確認打印機已安裝正確。'),Pchar(Application.Title),MB_ICONEXCLAMATION);
end;
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
myinifile:=tinifile.Create('files.ini');
try
lines:=tmenuitem.Create(self);
lines.Caption:=myinifile.ReadString('line','分割線','');
if lines.Caption<>'' then
file1.Insert(file1.Count-1,lines);
f1:=tmenuItem.Create(self);
f1.Caption:=myinifile.ReadString('path1','文件路徑','');
if f1.Caption<>'' then
file1.Insert(file1.Count-2,f1);
f2:=tmenuItem.Create(self);
f2.Caption:=myinifile.ReadString('path2','文件路徑','');
if f1.Caption<>'' then
file1.Insert(file1.Count-2,f2);
f3:=tmenuItem.Create(self);
f3.Caption:=myinifile.ReadString('path3','文件路徑','');
if f1.Caption<>'' then
file1.Insert(file1.Count-2,f3);
f4:=tmenuItem.Create(self);
f4.Caption:=myinifile.ReadString('path4','文件路徑','');
if f1.Caption<>'' then
file1.Insert(file1.Count-2,f4);
f1.OnClick:=myclick;
f2.OnClick:=myclick;
f3.OnClick:=myclick;
f4.OnClick:=myclick;
except
lines.Free;
f1.Free;
end;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
myinifile.Destroy;
end;
procedure TMainForm.ComboBox1Change(Sender: TObject);
begin
FormChild.richedit1.SelAttributes.Name:=combobox1.Text;
end;
procedure TMainForm.tb_boldClick(Sender: TObject);
begin
if tb_bold.Down then
FormChild.richedit1.SelAttributes.Style:=FormChild.richedit1.SelAttributes.Style+[fsbold]
else
FormChild.richedit1.SelAttributes.Style:=FormChild.richedit1.SelAttributes.Style-[fsbold];
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -