⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unotepad.pas

📁 利用DELPHI7来编写的一个记事本。不是非常的完善
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      self.Caption := FileName + ' - 记事本';
      RichEdit.Modified := false;
    end
  end
  else   //文件已存在
    if RichEdit.Modified then
    begin
      RichEdit.Lines.SaveToFile(FilePath);
      RichEdit.Modified := false;
    end;
end;

procedure TFrmNotepad.Mn11_4SavetoClick(Sender: TObject);//另存为
begin
  if SaveDialog.Execute then  //且确认保存
  begin
    RichEdit.Lines.SaveToFile(SaveDialog.FileName);
    FilePath := SaveDialog.FileName;
    FileName := Ntpd_GetFileName(FilePath);
    FileStatus := 1;
    self.Caption := FileName + ' - 记事本';
    RichEdit.Modified := false;
  end
end;

procedure TFrmNotepad.Mn11_6PageClick(Sender: TObject); //页面设置
begin
  try
    PrinterSetupDialog.Execute;
  except
    application.Messagebox('你可以执行你打印机有关的任务(例如页面设置或打印一个文档)之前,你必须已经安装打印机。你想现在安装打印机吗?',
                           pchar(FileName+ ' - 记事本'),MB_YESNO+MB_ICONQUESTION);
  end;
end;

procedure TFrmNotepad.Mn11_7PrintClick(Sender: TObject);//打印
begin
  try
    PrintDialog.Execute;
  except
    application.Messagebox('你可以执行你打印机有关的任务(例如页面设置或打印一个文档)之前,你必须已经安装打印机。你想现在安装打印机吗?',
                           pchar(FileName+ ' - 记事本'),MB_YESNO+MB_ICONQUESTION);
  end;
end;

procedure TFrmNotepad.Mn11_9ExitClick(Sender: TObject);//退出
begin
  close;
end;

procedure TFrmNotepad.Mn12_1CancelClick(Sender: TObject);//撤销
begin
  RichEdit.Undo;
end;

procedure TFrmNotepad.Mn12_3CutClick(Sender: TObject); //剪切
begin
  RichEdit.Perform(wm_cut,0,0);
end;

procedure TFrmNotepad.Mn12_4CopyClick(Sender: TObject);//复制
begin
  RichEdit.Perform(wm_copy,0,0);
end;

procedure TFrmNotepad.Mn12_5PlasterClick(Sender: TObject); //粘贴
begin
  RichEdit.Perform(wm_paste,0,0);
end;

procedure TFrmNotepad.Mn12_6DelClick(Sender: TObject);//删除
begin
  RichEdit.Perform(wm_clear,0,0);
end;

procedure TFrmNotepad.Mn12_8LookupClick(Sender: TObject);//查找
begin
  FindDialog.Execute;
end;

procedure TFrmNotepad.Mn12_9LookupNextClick(Sender: TObject);//查找下一个
begin
  if FindDialog.FindText = '' then
    FindDialog.Execute
  else
    FindDialogFind(Sender);
end;

procedure TFrmNotepad.Mn12_10ReplaceClick(Sender: TObject); //替换
begin
  ReplaceDialog.Execute;
end;

procedure TFrmNotepad.Mn12_11GotoClick(Sender: TObject);//转到
var
  col : integer;
begin
  FrmGotorow := TFrmGotorow.Create(application);
  FrmGotorow.row := RichEdit.caretpos.y+1;
  if FrmGotorow.ShowModal = IDOK then
  begin
    Col := 0;
    SetCaRichEdit(RichEdit, Row,Col);
  end;
  FrmGotorow.Release;
end;

procedure TFrmNotepad.Mn12_13AllClick(Sender: TObject);//全选
begin
 RichEdit.SelectAll;
end;

procedure TFrmNotepad.Mn12_14DateClick(Sender: TObject);//日期时间
var
  s1,s2:string;
begin
  s1:=DatetimeTostr(now());
  RichEdit.selText:=s1;
end;

procedure TFrmNotepad.Mn13_1NewlineClick(Sender: TObject);//自动换行
begin
  if Mn13_1Newline.Checked then
  begin
    Mn13_1Newline.Checked := false;
    RichEdit.WordWrap := false;
    RichEdit.ScrollBars := ssBoth;
    StatusBar.Visible := true;
    Mn14_1Status.Enabled := true;
  end
  else
  begin
    Mn13_1Newline.Checked := true;
    RichEdit.WordWrap := true;
    RichEdit.ScrollBars := ssVertical;
    StatusBar.Visible := false;
    Mn14_1Status.Enabled := false;
  end;
end;

procedure TFrmNotepad.Mn13_2FontClick(Sender: TObject); //字体
begin
  if FontDialog.Execute then
    RichEdit.Font := FontDialog.Font;
end;

procedure TFrmNotepad.Mn14_1StatusClick(Sender: TObject);//状态栏
begin
  if Mn14_1Status.Checked then
  begin
    Mn14_1Status.Checked := false;
    StatusBar.Visible := false;
  end
  else
  begin
    Mn14_1Status.Checked := true;
    StatusBar.Visible := true;
  end;
end;

procedure TFrmNotepad.Mn15_1MotifClick(Sender: TObject); //帮助主题
begin
  shellexecute(0,pchar('open'),pchar('c:\windows\help\notepad.chm'),nil,nil,sw_shownormal);
end;

procedure TFrmNotepad.Mn15_3AboutClick(Sender: TObject);//关于记事本
begin
  FrmNtpdAboutbox := TFrmNtpdAboutbox.Create(Application);
  FrmNtpdAboutbox.Left := FrmNotepad.Left+40;
  FrmNtpdAboutbox.Top := FrmNotepad.Top+80;
  FrmNtpdAboutbox.ShowModal;
  FrmNtpdAboutbox.Release;
end;

procedure TFrmNotepad.FindDialogFind(Sender: TObject); //点查找时触发事件
var
  FoundAt: LongInt;
  StartPos, SelectLength : Integer;//开始查找的起始位置,查找长度
begin
  {with RichEdit do
  begin
    if SelLength <> 0 then
      StartPos := SelStart + SelLength
    else
      StartPos := SelStart;
    SelectLength := Length(Text) - StartPos;
    FoundAt := FindText(FindDialog.FindText,StartPos,SelectLength, [stMatchCase]);
    if FoundAt <> -1 then
    begin
      RichEdit.SelStart := FoundAt;
      RichEdit.SelLength := Length(FindDialog.FindText);
    end
    else
      application.MessageBox(pchar('不能找到"'+FindDialog.FindText+'".'),'记事本',MB_ICONINFORMATION+MB_OK);
  end;}
  with sender as tfinddialog do
  if not SearchRichEdit(RichEdit,findtext,options) then
    application.MessageBox(pchar('不能找到"'+FindDialog.FindText+'".'),'记事本',MB_ICONINFORMATION+MB_OK)
  else
    RichEdit.SetFocus;
end;

procedure TFrmNotepad.RichEditKeyPress(Sender: TObject; var Key: Char);//键盘事件
var
  place : TPoint;
begin
  if Mn12_1Cancel.Enabled = false then
    Mn12_1Cancel.Enabled := true;
end;

procedure TFrmNotepad.Mn02EditClick(Sender: TObject); //点击菜单编辑
begin
  if RichEdit.Text ='' then//设置查找、查找下一个是否可用
  begin
    Mn12_8Lookup.Enabled := false;
    Mn12_9LookupNext.Enabled := false;
  end
  else
  begin
    Mn12_8Lookup.Enabled := true;
    Mn12_9LookupNext.Enabled := true;
  end;

  if RichEdit.SelLength <> 0 then //设置复制、剪切、粘贴是否可用
  begin
    Mn12_3Cut.Enabled := true;
    Mn12_4Copy.Enabled := true;
    Mn12_6Del.Enabled := true;
  end
  else
  begin
    Mn12_3Cut.Enabled := false;
    Mn12_4Copy.Enabled := false;
    Mn12_6Del.Enabled := false;
  end;
end;

procedure TFrmNotepad.ReplaceDialogFind(Sender: TObject); //点替换时触发事件
var
  //FoundAt: LongInt;
  //StartPos, ToEnd: Integer;
  found : boolean;
begin
  {with RichEdit do
  begin
    if SelLength <> 0 then
      StartPos := SelStart + SelLength
    else
      StartPos := 0;
    ToEnd := Length(Text) - StartPos;
    FoundAt := FindText(ReplaceDialog.FindText, StartPos, ToEnd, [stMatchCase]);
    if FoundAt <> -1 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(ReplaceDialog.FindText);
    end
    else showmessage('查找完成!');
  end;}
  with ReplaceDialog do
  begin
    if AnsiCompareText(RichEdit.SelText,findtext)=0 then
        RichEdit.SelText:=ReplaceText;
    found:=SearchRichEdit(RichEdit,findtext,options);

    while found and (frReplaceAll in Options) do
    begin
     RichEdit.SelText:=replacetext;
     found:=SearchRichEdit(RichEdit,findtext,options);
    end;

    if(not found) and (frReplace in options) then
      application.MessageBox(pchar('不能找到"'+FindDialog.FindText+'".'),'记事本',MB_ICONINFORMATION+MB_OK)
  end;
end;

procedure TFrmNotepad.RichEditMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer); //鼠标按下事件
var
  place : TPoint;
begin
  place := RichEdit.CaretPos;
  StatusBar.Panels[1].Text := '   Ln '+inttostr(place.Y+1)+',Col '+inttostr(place.x+1);
end;

procedure TFrmNotepad.RichEditKeyUp(Sender: TObject; var Key: Word;  //键盘弹起事件
  Shift: TShiftState);
var
  place : Tpoint;
begin
  place := RichEdit.CaretPos;
  StatusBar.Panels[1].Text := '   Ln '+inttostr(place.Y+1)+',Col '+inttostr(place.x+1);
end;

end.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -