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

📄 unotepad.pas

📁 类似于写字板,但此功能强大,可以扩展到许多地方
💻 PAS
📖 第 1 页 / 共 4 页
字号:
      if T[2]='0' then continue;
    end;
    Result:=Result+Number[Ord(T[I])-$30];
  end;
end;
//------------------------------------------------------------------------------
function TNotePadForm.PerformFind(Sender: TObject; FindString: String; SearchType: TSearchTypes):Boolean;
var
  FoundAt, StartPos, ToEnd: Integer;
  label Start;
begin
  with RichEdit do
  begin
    Start: StartPos:=SelStart+SelLength;
    ToEnd:=GetTextLen-StartPos;
    FoundAt:=FindText(FindString,StartPos,ToEnd,SearchType);
    if FoundAt<>-1 then
    begin
      SelStart:=FoundAt;
      SelLength:=Length(FindString);
      if Seltext='' then
      begin
        Selstart:=Selstart+2;
        goto Start;
      end;
      Result:=True;
    end
    else
    begin
      Application.MessageBox('查找完毕!','查找',MB_ICONEXCLAMATION);
      FindDialog.CloseDialog;
      Result:=False;
    end;
  end;
end;
//------------------------------------------------------------------------------
procedure TNotePadForm.UpdatePos;
begin
  StatusBar.Panels[2].Text:=Format('当前行: %-4d 列: %-4d', [RichEdit.CaretPos.y+1, RichEdit.CaretPos.x+1]);
end;

procedure TNotePadForm.SystemTimerTimer(Sender: TObject);
var
  SystemDateTime:TDateTime;
begin
  SystemDateTime:=Now();
  StatusBar.Panels[1].Text:='当前时间:['+DateTimeToStr(SystemDateTime)+']';
end;

procedure TNotePadForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  UpdateKeyStatus;
end;

procedure TNotePadForm.FormCreate(Sender: TObject);
var
  Filename: string;
  I: Integer;
begin
  //NotePadForm.ReadIni(Sender);
  UpdateKeyStatus;
  TimerRead.Enabled := False;
  CurrText.Name := DefFontData.Name;
  for I:=1 to ParamCount do
    Filename:=Filename+ParamStr(I)+'';
  if FileExists(Filename) then
    OpenFile(Sender,Filename);
  //if system.ParamCount<>0 then
 // if system.ParamStr(1)<>'' then
  //begin
    //Filename:=ParamStr(1);
    //RichEdit.Lines.LoadFromFile(FileName);
  //end;
end;

procedure TNotePadForm.RichEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
var
  I:Integer;
  C:TShortCut;
begin
  UpdateKeyStatus;
  if Key=Vk_Insert{45} then
  begin
    InsertMode:=not InsertMode;
    UpdateKeyStatus;
    exit;
  end;
  C:=ShortCut(Key,Shift);
  for I:=1 to MacroNumber do
    if c=MacroShortCut[I] then
      RichEdit.SelText:=MacroString[I];
end;

procedure TNotePadForm.MenuFileExitClick(Sender: TObject);
begin
  Close;
end;

procedure TNotePadForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  //WriteIni(Sender);
  Action:=caFree;
end;

procedure TNotePadForm.MenuWindowShowToolBarClick(Sender: TObject);
begin
  MenuWindowShowToolBar.Checked:=Not MenuWindowShowToolBar.Checked;
  if MenuWindowShowToolBar.Checked then
     begin
       MenuWindowShowToolBar.Checked:=True;
       ToolBar1.Visible:=True;
       ToolBar2.Visible:=True;
     end
  else
     begin
       MenuWindowShowToolBar.Checked:=False;
       ToolBar1.Visible:=False;
       ToolBar2.Visible:=False;
     end
end;

procedure TNotePadForm.MenuWindowStayOnTopClick(Sender: TObject);
begin
  with MenuWindowStayOnTop do
    Checked:=not Checked;
  if MenuWindowStayOnTop.Checked then
    SetWindowPos(Handle,Hwnd_Topmost,0,0,0,0,(SWP_NOMOVE Or SWP_NOSIZE))
  else
    SetWindowPos(Handle,Hwnd_Notopmost,0,0,0,0,(SWP_NOMOVE Or SWP_NOSIZE));
end;
{begin
  MenuWindowStayOnTop.Checked:=Not MenuWindowStayOnTop.Checked;
  if MenuWindowStayOnTop.Checked then
     begin
       MenuWindowStayOnTop.Checked:=True;
       NotePadForm.FormStyle:=fsStayOnTop;
     end
  else
     begin
       MenuWindowStayOnTop.Checked:=False;
       NotePadForm.FormStyle:=fsNormal;
     end;
end;}

procedure TNotePadForm.MenuWindowShowStatusBarClick(Sender: TObject);
begin
  MenuWindowShowStatusBar.Checked:=Not MenuWindowShowStatusBar.Checked;
  if MenuWindowShowStatusBar.Checked then
     begin
       MenuWindowShowStatusBar.Checked:=True;
       StatusBar.Visible:=True;
     end
  else
     begin
       MenuWindowShowStatusBar.Checked:=False;
       StatusBar.Visible:=False;
     end
end;
procedure TNotePadForm.MenuHelpAboutClick(Sender: TObject);
begin
  AboutBoxForm:=TAboutBoxForm.Create(Application);
  AboutBoxForm.ShowModal;
end;

procedure TNotePadForm.MenuFileSaveClick(Sender: TObject);
begin
  SaveFile(Sender,0);
end;

procedure TNotePadForm.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  CanClose:=not (CheckFileSave(Sender)=IDCANCEL);
end;

procedure TNotePadForm.MenuFileNewClick(Sender: TObject);
begin
  if CheckFileSave(Sender)<>IDCANCEL then
    begin
      RichEdit.Lines.Clear;
      FileName:='';
      UpdateCaption(Sender);
    end;
end;

procedure TNotePadForm.MenuFileOpenClick(Sender: TObject);
begin
  OpenFile(Sender,'');
end;

procedure TNotePadForm.MenuFileCloseClick(Sender: TObject);
begin
  MenuFileNewClick(Sender);
end;

procedure TNotePadForm.MenuFilePrintSetClick(Sender: TObject);
begin
  try
    PrinterSetupDialog.Execute
  except
    Application.MessageBox(Pchar('无法找到默认的打印机'+NewLine+'请确认打印机已安装正确。'),Pchar(Application.Title),MB_ICONEXCLAMATION);
  end;
end;
procedure TNotePadForm.MenuFilePrintClick(Sender: TObject);
begin
  try
    RichEdit.Print(FileName);
  except
    Application.MessageBox(Pchar('无法找到默认的打印机'+NewLine+'请确认打印机已安装正确。'),Pchar(Application.Title),MB_ICONEXCLAMATION);
  end;
end;

procedure TNotePadForm.MenuEditUndoClick(Sender: TObject);
begin
  RichEdit.Undo;
end;

procedure TNotePadForm.MenuEditCopyClick(Sender: TObject);
begin
  RichEdit.CopyToClipboard;
end;

procedure TNotePadForm.MenuEditPasteClick(Sender: TObject);
begin
  RichEdit.PasteFromClipboard;
end;

procedure TNotePadForm.MenuEditDeleteClick(Sender: TObject);
begin
  RichEdit.ClearSelection;
end;

procedure TNotePadForm.MenuEditBackClick(Sender: TObject);
begin
  //RichEdit.Repaint;
end;

procedure TNotePadForm.MenuEditCutClick(Sender: TObject);
begin
  RichEdit.CutToClipboard;
end;

procedure TNotePadForm.MenuEditSelectAllClick(Sender: TObject);
begin
  RichEdit.SelectAll;
end;

procedure TNotePadForm.MenuEditSelectLineClick(Sender: TObject);
begin
  with RichEdit do
  begin
    SelStart:=SelStart-CaretPos.x;
    SelLength:=Length(Lines[CaretPos.y]);
  end;
end;

procedure TNotePadForm.MenuEditDeleteLineClick(Sender: TObject);
begin
  RichEdit.Lines.Delete(RichEdit.CaretPos.y);
end;

procedure TNotePadForm.MenuFontSetClick(Sender: TObject);
begin
  with FontDialog do
  begin
    Font:=RichEdit.Font;
    if Execute then
      RichEdit.Font:=Font;
  end;
  RichEdit.Refresh;
end;

procedure TNotePadForm.MenuFontDefaultClick(Sender: TObject);
begin
  with RichEdit do
  begin
    Font.Color:=clWindowText;
    Font.Size:=10;
    Font.Name:='宋体';
    Refresh;
  end;
end;

procedure TNotePadForm.MenuEditWrapClick(Sender: TObject);
var
  Pos:Integer;
begin
  with RichEdit,MenuEditWrap do
  begin
    Pos:=SelStart;
    Checked:=Not Checked;
    WordWrap:=Checked;
    if WordWrap then
      ScrollBars:=ssVertical
    else
      ScrollBars:=ssBoth;
    SelStart:=Pos;
  end;
end;

procedure TNotePadForm.MenuFileSaveAsClick(Sender: TObject);
begin
  SaveFile(Sender,1);
end;

procedure TNotePadForm.MenuInsertDayClick(Sender: TObject);
const
  EDay:array[1..7] of string=('星期日','星期一','星期二','星期三','星期四','星期五','星期六');
var
  Day:Integer;
begin
  Day:=DayOfWeek(Now);          //星期日是第一天
  with RichEdit do
   case DayFormat of
     0:SelText:=EDay[Day];
     1:SelText:=EDay[Day][1]+EDay[Day][2]+EDay[Day][3];      //取前三个字母
     2:{if d=1 then
         SelText:='星期日'
       else
         SelText:='星期'+Number[d-1];}
         SelText:=LongDayNames[Day];
   end;
end;
procedure TNotePadForm.MenuInsertDateClick(Sender: TObject);
var
  S,T:String;
  I,y,m,d:Word;
begin
  DecodeDate(Now,y,m,d);
  case DateFormat of
    0:s:=IntToStr(y)+'-'+IntToStr(m)+'-'+IntToStr(d);
    1:s:=IntToStr(y)+'.'+IntToStr(m)+'.'+IntToStr(d);
    2:s:=IntToStr(y)+'年'+IntToStr(m)+'月'+IntToStr(d)+'日';
    3:begin
      T:=IntToStr(y);
      for I:=1 to length(T) do
        S:=s+Number[ord(T[I])-$30];
      S:=S+'年'+IntToChi(m)+'月'+IntToChi(d)+'日';
      end;
  end;
  RichEdit.SelText:=S;
end;
procedure TNotePadForm.MenuInsertTimeClick(Sender: TObject);
var
  S:String;
  I,hh,mm,ss:Word;
begin
  DecodeTime(Now,hh,mm,ss,I);
  case TimeFormat of
    0:S:=IntToStr(hh)+':'+IntToStr(mm)+':'+IntToStr(ss);
    1:begin
        if hh<10 then   S:=S+'0';
        S:=S+IntToStr(hh)+':';
        if mm<10 then   S:=S+'0';
        S:=s+IntToStr(mm)+':';
        if ss<10 then   S:=S+'0';
        S:=s+IntToStr(ss);
      end;
    2:S:=IntToStr(hh)+'点'+IntToStr(mm)+'分'+IntToStr(ss)+'秒';
    3:S:=s+IntToChi(hh)+'点'+IntToChi(mm)+'分'+IntToChi(ss)+'秒';
  end;
  RichEdit.SelText:=S;
end;
procedure TNotePadForm.MenuInsertCharClick(Sender: TObject);
begin
  FormTable:=TFormTable.Create(Application);
  FormTable.Show;
end;

procedure TNotePadForm.MenuInsertFileClick(Sender: TObject);
//var
//  InsertString:TStringlist;
begin
  with OpenDialog do
  begin
    Filter:=DefaultFilter;
    InitialDir:=ExtractFilePath(FileName);
    if Execute then
      try
        with RichEdit do
          SelStart:=SelStart+SelLength;
          InsertString:=TStringlist.Create;
          InsertString.LoadFromFile(OpenDialog.FileName);
          RichEdit.SelText:=InsertString.Text;
      finally
        InsertString.Free;
      end;
  end;
end;
procedure TNotePadForm.MenuSearchFindClick(Sender: TObject);
begin
  with FindDialog do
  begin
    Position:=Point(RichEdit.Left+RichEdit.Width div 2,RichEdit.Top);
    FindText:=RichEdit.SelText;
    Execute;
  end;
end;
procedure TNotePadForm.MenuSearchPriorClick(Sender: TObject);
begin
  Application.MessageBox(Pchar('Sorry!本功能有待完善。'),Pchar(Application.Title),MB_ICONEXCLAMATION);
end;

procedure TNotePadForm.MenuSearchNextClick(Sender: TObject);
begin
  if Length(FindDialog.FindText)>0 then
    FindDialogFind(Sender)
  else
    MenuSearchFindClick(Sender);
end;

procedure TNotePadForm.MenuSearchReplaceClick(Sender: TObject);
begin
  with ReplaceDialog do
  begin
    Position:=Point(RichEdit.Left+RichEdit.Width div 2,RichEdit.Top);
    if RichEdit.SelLength>0 then
      FindText:=RichEdit.SelText
    else
      if Length(FindDialog.FindText)>0 then
        FindText:=FindDialog.FindText;
    Execute;
  end;
end;

procedure TNotePadForm.MenuSearchGoToLineClick(Sender: TObject);
var
  L:Integer;
  Tan:Boolean;
begin
  L:=StrToInt(InputBox('请输入行号:', '', ''));
  with RichEdit do
  begin
    Tan:=Modified;
    if (L>0) or(L<=Lines.Count) then
    begin
      Lines.Insert(L-1,'');
      Lines.Delete(L-1);
    end;
    Modified:=Tan;
  end;
end;

procedure TNotePadForm.MenuFontBiggerClick(Sender: TObject);
begin
  ChangeFontSize(Sender,1);
end;

procedure TNotePadForm.MenuFontSmallerClick(Sender: TObject);
begin
  ChangeFontSize(Sender,-1);
end;

procedure TNotePadForm.MenuColorForeClick(Sender: TObject);
begin
  with ColorDialog do
  begin
    Color:=Richedit.Font.Color;
    if Execute then
      Richedit.Font.Color:=Color;
  end;
end;
procedure TNotePadForm.MenuColorBackClick(Sender: TObject);
begin
  with ColorDialog do
  begin
    Color:=RichEdit.Color;

⌨️ 快捷键说明

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