程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 文件編輯器

文件編輯器

編輯:Delphi

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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved