文件编辑器

页面导航:首页 > 软件编程 > Delphi > 文件编辑器

文件编辑器

来源: 作者: 时间:2016-01-15 15:17 【

unit Unit1;interfaceuses COmObj,WordXP,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls, OleCtnrs, ComCtrls, Buttons, ToolWin;typ...

unit Unit1;


interface


uses
  COmObj,WordXP,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, OleCtnrs, ComCtrls, Buttons, ToolWin;


type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    N10: TMenuItem;
    N15: TMenuItem;
    N16: TMenuItem;
    N17: TMenuItem;
    N18: TMenuItem;
    N19: TMenuItem;
    N20: TMenuItem;
    N21: TMenuItem;
    N22: TMenuItem;
    N23: TMenuItem;
    N24: TMenuItem;
    N25: TMenuItem;
    N26: TMenuItem;
    N27: TMenuItem;
    N28: TMenuItem;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    SaveDialog1: TSaveDialog;
    N11: TMenuItem;
    ColorDialog1: TColorDialog;
    Button1: TButton;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    ToolButton2: TToolButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    ToolBar2: TToolBar;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    N12: TMenuItem;
    N13: TMenuItem;
    N14: TMenuItem;
    ToolButton3: TToolButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    ToolButton4: TToolButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    N29: TMenuItem;
    OleContainer1: TOleContainer;
    procedure N2Click(Sender: TObject);
    procedure N11Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure N9Click(Sender: TObject);
    procedure N8Click(Sender: TObject);
    procedure N10Click(Sender: TObject);
    procedure N17Click(Sender: TObject);
    procedure N18Click(Sender: TObject);
    procedure N20Click(Sender: TObject);
    procedure N21Click(Sender: TObject);
    procedure N22Click(Sender: TObject);
    procedure N24Click(Sender: TObject);
    procedure N27Click(Sender: TObject);
    procedure N28Click(Sender: TObject);
    procedure N25Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure newClick(Sender: TObject);
   // procedure OpenClick(Sender: TObject);
    procedure OpenClick(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure N29Click(Sender: TObject);
    procedure N13Click(Sender: TObject);
    procedure N14Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure alignnment(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure SpeedButton10Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);


  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;


implementation


{$R *.dfm}
 uses Unit2;
 var
   Filename:string;
 //------菜单栏-文件
procedure TForm1.N2Click(Sender: TObject);
var
      wordapp, doc: olevariant;
      strs: TStringList;
begin


   if opendialog1.Execute then    //打开文件
     begin
       strs:=TStringList.Create;
       wordapp := createOleobject('Word.application');
       try
         doc := wordapp.Documents.Open(FileName := OpenDialog1.FileName);
        memo1.Text := doc.range.Text;
        doc.Close;
       finally
         wordapp.quit;
        strs.Free;
       end;
     end;


    // memo1.Lines.LoadFromFile(
     //opendialog1.FileName);


end;


procedure TForm1.N11Click(Sender: TObject);
begin
    if savedialog1.Execute  then//保存文件
      memo1.Lines.SaveToFile(
      savedialog1.FileName);
end;


procedure TForm1.N6Click(Sender: TObject);
begin
   if Messagedlg('是否退出',
   Mtconfirmation,[mbYes,mbNo],0)=mrYes then //退出
     form1.Close;
end;
//---------编辑子菜单--编辑


procedure TForm1.N9Click(Sender: TObject);
begin
   Memo1.CutToClipboard;      //剪切
end;


procedure TForm1.N8Click(Sender: TObject);
begin
    Memo1.CopyToClipboard;          //拷贝
end;


procedure TForm1.N10Click(Sender: TObject);
begin
   Memo1.PasteFromClipboard;              //粘贴
end;


procedure TForm1.N17Click(Sender: TObject);
begin
    Memo1.SelectAll;//全选
end;


procedure TForm1.N18Click(Sender: TObject);
begin
    Memo1.Lines.Clear;//全清
end;
//--------------格式子菜单


procedure TForm1.N20Click(Sender: TObject);
begin
   N20.Checked:=true;    //左对齐,只要它被选中,则其他两个居中和右对齐就为False
   Memo1.Alignment:=taLeftJustify;
end;


procedure TForm1.N21Click(Sender: TObject);
begin
    N21.Checked:=true;  //居中
    Memo1.Alignment:=taCenter;
end;


procedure TForm1.N22Click(Sender: TObject);
begin
   N22.Checked:=true;  //右对齐
    Memo1.Alignment:=taRightJustify;
end;


procedure TForm1.N24Click(Sender: TObject);
begin
    if colordialog1.Execute then//字体颜色
      Memo1.Font.Color:=colordialog1.Color;
end;


procedure TForm1.N27Click(Sender: TObject);
begin
   N27.Checked:=not N27.Checked;      //粗体
   if N27.Checked then
     Memo1.Font.Style:=Memo1.Font.Style+[fsBold]
   else
     Memo1.Font.Style:=Memo1.Font.Style-[fsBold];
end;


procedure TForm1.N28Click(Sender: TObject);
begin
    N28.Checked:=not N28.Checked;      //斜体
   if N28.Checked then
     Memo1.Font.Style:=Memo1.Font.Style+[fsItalic]
   else
     Memo1.Font.Style:=Memo1.Font.Style-[fsItalic];
end;


procedure TForm1.N25Click(Sender: TObject);
begin
   if colordialog1.Execute then//字体颜色
      Memo1.Color:=colordialog1.Color;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
    Form2.ShowModal;
end;
 //------初始化
procedure TForm1.FormShow(Sender: TObject);
begin
   Filename:='';
   Memo1.Lines.Clear;
   ComboBox1.Items:=Screen.Fonts;
end;
//------工具栏一


procedure TForm1.newClick(Sender: TObject);
begin
    Memo1.Lines.Clear;  //文件--新建
    Filename:='';
end;

 

 


procedure TForm1.OpenClick(Sender: TObject);
begin
    if opendialog1.Execute  then    //文件--打开
      begin
        Memo1.Lines.LoadFromFile(
        opendialog1.FileName);
        Filename:=opendialog1.FileName;
        Memo1.SetFocus;
      end;
end;


procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
   if (Filename='') then
     if savedialog1.Execute then
       Memo1.Lines.SaveToFile(
       savedialog1.FileName)
     else
       Memo1.Lines.SaveToFile(
       Filename);
end;


procedure TForm1.N29Click(Sender: TObject);
begin
    Memo1.Undo;//编辑--撤销
end;


procedure TForm1.N13Click(Sender: TObject);
begin
   N13.Checked:=not N13.Checked;
   if N13.Checked then         //视图--工具栏一
     ToolBar1.Visible:=true
   else
     ToolBar1.Visible:=false;
end;


procedure TForm1.N14Click(Sender: TObject);
begin
   N14.Checked:=not N14.Checked;
   if N14.Checked then         //视图--工具栏二
     ToolBar2.Visible:=true
   else
     ToolBar2.Visible:=false;
end;

 


procedure TForm1.alignnment(Sender: TObject);
begin
   if speedbutton5.Down  then      //对齐
     Memo1.Alignment:=taLeftJustify
   else if speedbutton6.Down then
     Memo1.Alignment:=taCenter
   else
     Memo1.Alignment:=taRightJustify;
end;


procedure TForm1.SpeedButton8Click(Sender: TObject);
begin
   if (SpeedButton8.Down) then        //粗体
     Memo1.Font.Style:=Memo1.Font.Style+[fsBold]
   else
     Memo1.Font.Style:=Memo1.Font.Style-[fsBold];
end;


procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
   if (SpeedButton9.Down) then        //斜体
     Memo1.Font.Style:=Memo1.Font.Style+[fsItalic]
   else
     Memo1.Font.Style:=Memo1.Font.Style-[fsItalic];
end;


procedure TForm1.SpeedButton10Click(Sender: TObject);
begin
   if (SpeedButton10.Down) then        //下划线
     Memo1.Font.Style:=Memo1.Font.Style+[fsUnderline]
   else
     Memo1.Font.Style:=Memo1.Font.Style-[fsUnderline];
end;


procedure TForm1.SpeedButton11Click(Sender: TObject);
begin
   Memo1.CutToClipboard;      //剪切
end;


procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
   Memo1.CopyToClipboard;          //拷贝
end;


procedure TForm1.SpeedButton13Click(Sender: TObject);
begin
   Memo1.PasteFromClipboard;              //粘贴
end;
//---------工具栏二
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
   Memo1.Font.Name:=Combobox1.Text;  //选择字体
end;


procedure TForm1.ComboBox2Change(Sender: TObject);
begin
   Memo1.Font.Size:=StrToInt(Combobox2.Text);//选择字体大小
end;


end.

Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<