字窗口文件

unit Uchildform;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, ComCtrls;

type
  TChildForm = class(TForm)
    MainMenu1: TMainMenu;
    Nedit: TMenuItem;
    No: TMenuItem;
    Nnudo: TMenuItem;
    N1: TMenuItem;
    Ncut: TMenuItem;
    Ncopy: TMenuItem;
    Nplase: TMenuItem;
    N2: TMenuItem;
    Nselectall: TMenuItem;
    N3: TMenuItem;
    Nfind: TMenuItem;
    Nreplace: TMenuItem;
    Nfontset: TMenuItem;
    Nduqi: TMenuItem;
    RichEdit1: TRichEdit;
    FindDialog1: TFindDialog;
    PopupMenu1: TPopupMenu;
    pmcut: TMenuItem;
    pmcopy: TMenuItem;
    pmpaste: TMenuItem;
    N7: TMenuItem;
    pmselectall: TMenuItem;
    N9: TMenuItem;
    pmleft: TMenuItem;
    pmcenter: TMenuItem;
    pmright: TMenuItem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure NcutClick(Sender: TObject);
    procedure NcopyClick(Sender: TObject);
    procedure NplaseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure NfontsetClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure NnudoClick(Sender: TObject);
    procedure NselectallClick(Sender: TObject);
    procedure RichEdit1SelectionChange(Sender: TObject);
    procedure RichEdit1Change(Sender: TObject);
    procedure NfindClick(Sender: TObject);
    procedure FindDialog1Find(Sender: TObject);
    procedure pmcutClick(Sender: TObject);
    procedure pmcopyClick(Sender: TObject);
    procedure pmpasteClick(Sender: TObject);
    procedure pmselectallClick(Sender: TObject);
    procedure pmleftClick(Sender: TObject);
    procedure pmcenterClick(Sender: TObject);
    procedure pmrightClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ChildForm: TChildForm;

implementation

uses Umainform;

{$R *.dfm}

procedure TChildForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  action:=cafree;
  if mdiChildcount=0 then
  begin
  mainform1.TBsave.Enabled:=false;
  mainform1.TBprint.Enabled:=false;
  mainform1.TBprintview.Enabled:=false;
  mainform1.TBpaste.Enabled:=false;
  mainform1.TBundo.Enabled:=false;
  mainform1.TBbold.Enabled:=false;
  mainform1.TBitalic.Enabled:=false;
  mainform1.TBunderline.Enabled:=false;
  mainform1.TBfontcolor.Enabled:=false;
  mainform1.TBleft.Enabled:=false;
  mainform1.TBcenter.Enabled:=false;
  mainform1.TBright.Enabled:=false;
  mainform1.CBfont.Enabled:=false;
  mainform1.CBfontsize.Enabled:=false;
  end;
end;

procedure TChildForm.NcutClick(Sender: TObject);
begin
  Richedit1.CutToClipboard;
end;

procedure TChildForm.NcopyClick(Sender: TObject);
begin
  Richedit1.CopyToClipboard;
end;

procedure TChildForm.NplaseClick(Sender: TObject);
begin
  Richedit1.PasteFromClipboard;
end;

procedure TChildForm.FormCreate(Sender: TObject);
begin
  MainForm1.CBfont.Items:=screen.Fonts;
  MainForm1.CBfont.Text:=richedit1.Font.Name;
  MainForm1.CBfontsize.Text:=inttostr(richedit1.Font.size);
  mainform1.TBprint.Enabled:=true;
  mainform1.TBprintview.Enabled:=true;
  mainform1.TBpaste.Enabled:=true;
  mainform1.TBbold.Enabled:=true;
  mainform1.TBitalic.Enabled:=true;
  mainform1.TBunderline.Enabled:=true;
  mainform1.TBfontcolor.Enabled:=true;
  mainform1.TBleft.Enabled:=true;
  mainform1.TBcenter.Enabled:=true;
  mainform1.TBright.Enabled:=true;
  mainform1.CBfont.Enabled:=true;
  mainform1.CBfontsize.Enabled:=true;
  RichEdit1.Modified:=false;
end;

procedure TChildForm.NfontsetClick(Sender: TObject);
begin
  Mainform1.Fontdialog1.Font.Assign(Richedit1.SelAttributes);
  if Mainform1.Fontdialog1.Execute then
    Richedit1.SelAttributes.Assign(Mainform1.Fontdialog1.Font);
  Richedit1.SetFocus;
end;

procedure TChildForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  r: word;
begin
  if richedit1.Modified then
  begin
    r:=messagedlg('文档已被修改,是否保存?',mtConfirmation,[mbYes,mbNo,mbCancel],1);
    if r=mryes then
      begin
        if pos('文档',self.Caption)<>0 then
          begin
            if mainform1.savedialog1.Execute then
              begin
                self.Caption:=mainform1.savedialog1.FileName;
                self.RichEdit1.Lines.SaveToFile(self.Caption);

              end;
          end
        else
          begin
            self.RichEdit1.Lines.SaveToFile(self.Caption);
          end;
      end
    else if r=mrcancel then
      canclose:=false;

  end;
end;

procedure TChildForm.NnudoClick(Sender: TObject);
begin
  Richedit1.Undo;
end;

procedure TChildForm.NselectallClick(Sender: TObject);
begin
  Richedit1.SelectAll;
end;

procedure TChildForm.RichEdit1SelectionChange(Sender: TObject);
begin
  mainform1.TBbold.Down:=(fsbold in richedit1.SelAttributes.Style);
  mainform1.TBitalic.Down:=(fsItalic in richedit1.SelAttributes.Style);
  mainform1.TBunderline.Down:=(fsUnderLine in richedit1.SelAttributes.Style);

  case richedit1.Paragraph.Alignment of
    taLeftJustify: mainform1.TBLeft.Down:=True ;
    tacenter: mainform1.TBcenter.Down:=True ;
    taRightJustify: mainform1.TBRight.Down:=True;
  end;

  mainform1.CBfont.Text:=richedit1.SelAttributes.Name;
  mainform1.CBfontsize.Text:=inttostr(richedit1.SelAttributes.Size);

  if richedit1.SelLength<>0 then
    begin
      mainform1.TBcut.Enabled:=true;
      mainform1.TBcopy.Enabled:=true;
    end
  else
    begin
      mainform1.TBcut.Enabled:=false;
      mainform1.TBcopy.Enabled:=false;
    end;
end;

procedure TChildForm.RichEdit1Change(Sender: TObject);
begin
  mainform1.TBundo.Enabled:=true;
  mainform1.TBsave.Enabled:=true;
end;

procedure TChildForm.NfindClick(Sender: TObject);
begin
  finddialog1.Position:=point(richedit1.Left+richedit1.Width,richedit1.Top+richedit1.Height);
  finddialog1.FindText:=richedit1.SelText;
  finddialog1.Execute;
end;

procedure TChildForm.FindDialog1Find(Sender: TObject);
var
  FoundAt:LongInt;
  StartPos,ToEnd:Integer;
begin
  if richedit1.SelLength=0 then
    StartPos:=0
  else
    StartPos:=richedit1.SelStart+richedit1.SelLength;
    Toend:=Length(richedit1.Text)-StartPos;
    FoundAt:=richedit1.FindText(finddialog1.FindText,StartPos,Toend,[stMatchCase]);

  if FoundAt<>-1 then
    begin
      richedit1.SetFocus;
      richedit1.SelStart:=FoundAt;
      richedit1.SelLength:=length(finddialog1.FindText);
    end
  else
    if (MessageDlg('搜索完毕,未找到所查找的字符串,是否重新搜索?',mtConfirmation,[mbYes,mbNo],0)=mrYes) then
      richedit1.Sellength:=0
    else
      finddialog1.CloseDialog;
end;

procedure TChildForm.pmcutClick(Sender: TObject);
begin
  RichEdit1.CutToClipboard;
end;

procedure TChildForm.pmcopyClick(Sender: TObject);
begin
  richedit1.CopyToClipboard;
end;

procedure TChildForm.pmpasteClick(Sender: TObject);
begin
  richedit1.PasteFromClipboard;
end;

procedure TChildForm.pmselectallClick(Sender: TObject);
begin
  richedit1.SelectAll;
end;

procedure TChildForm.pmleftClick(Sender: TObject);
begin
  richedit1.Paragraph.Alignment:=taleftjustify;
end;

procedure TChildForm.pmcenterClick(Sender: TObject);
begin
  richedit1.Paragraph.Alignment:=tacenter;
end;

procedure TChildForm.pmrightClick(Sender: TObject);
begin
  richedit1.Paragraph.Alignment:=tarightjustify;
end;

end.

你可能感兴趣的:(文件)