unit Umainform;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ToolWin, Menus, ImgList, StdCtrls,Uchildform;
type
TMainForm1 = class(TForm)
MainMenu1: TMainMenu;
Nfile: TMenuItem;
Nnew: TMenuItem;
Nopen: TMenuItem;
Nclose: TMenuItem;
N1: TMenuItem;
Nsave: TMenuItem;
Nsaveas: TMenuItem;
N2: TMenuItem;
Npageset: TMenuItem;
Nprintview: TMenuItem;
Nprint: TMenuItem;
N3: TMenuItem;
Nexit: TMenuItem;
Nwindow: TMenuItem;
Ntile: TMenuItem;
Ncascade: TMenuItem;
Nhelp: TMenuItem;
Nabout: TMenuItem;
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolBar2: TToolBar;
TBnew: TToolButton;
TBopen: TToolButton;
TBsave: TToolButton;
TBcut: TToolButton;
TBcopy: TToolButton;
TBpaste: TToolButton;
TBundo: TToolButton;
CBfont: TComboBox;
CBfontsize: TComboBox;
ToolButton14: TToolButton;
TBbold: TToolButton;
TBitalic: TToolButton;
TBunderline: TToolButton;
ToolButton18: TToolButton;
ToolButton20: TToolButton;
TBleft: TToolButton;
TBcenter: TToolButton;
TBright: TToolButton;
ImageList1: TImageList;
StatusBar1: TStatusBar;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
NArrangeAll: TMenuItem;
FontDialog1: TFontDialog;
ColorDialog1: TColorDialog;
PopupMenu1: TPopupMenu;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
procedure NnewClick(Sender: TObject);
procedure NcloseClick(Sender: TObject);
procedure NopenClick(Sender: TObject);
procedure NsaveClick(Sender: TObject);
procedure NcascadeClick(Sender: TObject);
procedure NArrangeAllClick(Sender: TObject);
procedure NtileClick(Sender: TObject);
procedure TBcutClick(Sender: TObject);
procedure TBcopyClick(Sender: TObject);
procedure TBpasteClick(Sender: TObject);
procedure TBundoClick(Sender: TObject);
procedure CBfontChange(Sender: TObject);
procedure CBfontsizeChange(Sender: TObject);
procedure TBboldClick(Sender: TObject);
procedure TBitalicClick(Sender: TObject);
procedure TBunderlineClick(Sender: TObject);
procedure TBleftClick(Sender: TObject);
procedure NsaveasClick(Sender: TObject);
procedure TBfontcolorClick(Sender: TObject);
procedure NprintClick(Sender: TObject);
procedure NexitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm1: TMainForm1;
achild: TChildForm;
fname: string;
implementation
{$R *.dfm}
procedure TMainForm1.NnewClick(Sender: TObject);
begin
achild:=TChildForm.Create(application);
achild.RichEdit1.Clear;
getdir(0,fname);
fname:=fname+'\文档' +inttostr(mdiChildCount);
achild.Caption:=fname;
end;
procedure TMainForm1.NcloseClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild.ActiveMDIChild.Close;
end;
procedure TMainForm1.NopenClick(Sender: TObject);
var
i:integer;
curchild:TChildForm;
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;
end
else
i:=i-1;
if not find then
begin
achild:=TChildForm.Create(application);
achild.RichEdit1.Lines.LoadFromFile(opendialog1.FileName);
achild.Caption:=opendialog1.FileName;
fname:=opendialog1.FileName;
end;
end;
curchild:=self.activemdichild as TChildForm;
curchild.richedit1.Modified:=false;
end;
procedure TMainForm1.NsaveClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
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;
mainform1.TBsave.Enabled:=false;
mainform1.TBundo.Enabled:=false;
curchild.richedit1.Modified:=false;
end;
procedure TMainForm1.NcascadeClick(Sender: TObject);
begin
MainForm1.Cascade;
end;
procedure TMainForm1.NArrangeAllClick(Sender: TObject);
begin
MainForm1.ArrangeIcons;
end;
procedure TMainForm1.NtileClick(Sender: TObject);
begin
MainForm1.Tile;
end;
procedure TMainForm1.TBcutClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
curchild.RichEdit1.CutToClipboard;
end;
procedure TMainForm1.TBcopyClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
curchild.RichEdit1.CopyToClipboard;
end;
procedure TMainForm1.TBpasteClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
curchild.RichEdit1.PasteFromClipboard;
end;
procedure TMainForm1.TBundoClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
curchild.RichEdit1.Undo;
end;
procedure TMainForm1.CBfontChange(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if CBfont.text<>'' then
curchild.RichEdit1.SelAttributes.Name:=CBfont.text;
end;
procedure TMainForm1.CBfontsizeChange(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if CBfontsize.text<>'' then
curchild.RichEdit1.SelAttributes.Size:=strtoint(CBfontsize.Text);
end;
procedure TMainForm1.TBboldClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if TBbold.Down then
curchild.richedit1.SelAttributes.Style:=curchild.richedit1.SelAttributes.Style+[fsBold]
else
curchild.richedit1.SelAttributes.Style:=curchild.richedit1.SelAttributes.Style-[fsBold]
end;
procedure TMainForm1.TBitalicClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if TBItalic.Down then
curchild.richedit1.SelAttributes.Style:=curchild.richedit1.SelAttributes.Style+[fsItalic]
else
curchild.richedit1.SelAttributes.Style:=curchild.richedit1.SelAttributes.Style-[fsItalic];
end;
procedure TMainForm1.TBunderlineClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if TBunderline.Down then
curchild.richedit1.SelAttributes.Style:=curchild.richedit1.SelAttributes.Style+[fsUnderline]
else
curchild.richedit1.SelAttributes.Style:=curchild.richedit1.SelAttributes.Style-[fsUnderline];
end;
procedure TMainForm1.TBleftClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if sender=TBLeft then
curchild.richedit1.Paragraph.Alignment:=taLeftJustify
else if sender=TBcenter then
curchild.richedit1.Paragraph.Alignment:=taCenter
else
curchild.richedit1.Paragraph.Alignment:=taRightJustify;
end;
procedure TMainForm1.NsaveasClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if savedialog1.Execute then
curchild.richedit1.Lines.SaveToFile(savedialog1.FileName)
end;
procedure TMainForm1.TBfontcolorClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if colordialog1.Execute then
curchild.RichEdit1.SelAttributes.Color:=ColorDialog1.Color;
end;
procedure TMainForm1.NprintClick(Sender: TObject);
var
curchild:TChildForm;
begin
curchild:=self.activemdichild as TChildForm;
if printdialog1.Execute then
curchild.RichEdit1.Print(printdialog1.Name)
end;
procedure TMainForm1.NexitClick(Sender: TObject);
begin
mainform1.Close;
end;
end.