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

📄 unotepad.pas

📁 类似于写字板,但此功能强大,可以扩展到许多地方
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    if Execute then
      RichEdit.Color:=Color;
  end;
end;
procedure TNotePadForm.MenuColorDefaultForeClick(Sender: TObject);
begin
  RichEdit.Font.Color:=DefForeColor;
end;

procedure TNotePadForm.MenuColorDefaultBackClick(Sender: TObject);
begin
  RichEdit.Color:=DefBackColor;
end;

procedure TNotePadForm.MenuFuntionRunClick(Sender: TObject);
begin
  with OpenDialog do
  begin
    Filter:=ExecFilter;
    InitialDir:=ExtractFilePath(Application.ExeName);
    if Execute then
      WinExec(Pchar(OpenDialog.FileName),1);
  end;
end;
procedure TNotePadForm.MenuFuntionDiaryClick(Sender: TObject);
var
  S:Integer;
begin
  S:=DateFormat;
  DateFormat:=2;
  MenuInsertDateClick(Sender);
  DateFormat:=S;

  RichEdit.Text:=RichEdit.Text+#9#9;

  S:=DayFormat;
  DayFormat:=2;
  RichEdit.SelStart:=RichEdit.GetTextLen;
  MenuInsertDayClick(Sender);
  DayFormat:=s;

  RichEdit.Text:=RichEdit.Text+#9#9+'晴';
  RichEdit.Lines.Add('  今天是...');
end;

procedure TNotePadForm.MenuWindowOpenAgainClick(Sender: TObject);
begin
  WinExec(Pchar(Application.ExeName),1);
end;

procedure TNotePadForm.FormResize(Sender: TObject);
begin
  with RichEdit do
  begin
    Top:=0;
    Left:=0;
    Width:=RichEdit.ClientWidth;
    Height:=RichEdit.ClientHeight;
    if Toolbar1.Visible then
    begin
      Top:=Top+Toolbar1.Height;
      Height:=Height-Toolbar1.Height;
    end;
    if Toolbar2.Visible then
    begin
      Top:=Top+Toolbar2.Height;
      Height:=Height-Toolbar2.Height;
    end;
  end;
end;
procedure TNotePadForm.MenuOptionClick(Sender: TObject);
begin
  FormOption:=TFormOption.Create(Application);
  FormOption.ShowModal;
end;

procedure TNotePadForm.MenuOptionSetClick(Sender: TObject);
begin
  FormOption:=TFormOption.Create(Application);
  FormOption.ShowModal;
end;

procedure TNotePadForm.MenuFuntionAddLineNumberClick(Sender: TObject);
var
  I:Integer;
begin
  try
    Screen.Cursor:=crHourGlass;
    RichEdit.Visible:=False;
    with RichEdit.Lines do
      for I:=0 to Count do
       Strings[I]:=IntToStr(I+1)+#9+Strings[I];
  finally
    RichEdit.Visible:=True;
    Screen.Cursor:=crDefault;
  end;
end;
procedure TNotePadForm.ToolButtonBoldClick(Sender: TObject);
begin
  with RichEdit.Font do
    if ToolButtonBold.Down then
      CurrText.Style:=Style+[fsBold]
    else
      CurrText.Style:=Style-[fsBold];
end;

procedure TNotePadForm.ToolButtonItalizeClick(Sender: TObject);
begin
  with RichEdit.Font do
    if ToolButtonItalize.Down then
      CurrText.Style:=Style+[fsItalic]
    else
      CurrText.Style:=Style-[fsItalic];
end;
procedure TNotePadForm.ToolButtonUnderLineClick(Sender: TObject);
begin
  with RichEdit.Font do
    if ToolButtonUnderline.Down then
      CurrText.Style:=Style+[fsUnderline]
    else
      CurrText.Style:=Style-[fsUnderline];
end;

procedure TNotePadForm.ToolButtonLeftClick(Sender: TObject);
begin
  RichEdit.Paragraph.Alignment:=taLeftJustify;
end;

procedure TNotePadForm.ToolButtonCenterClick(Sender: TObject);
begin
  RichEdit.Paragraph.Alignment:=taCenter;
end;

procedure TNotePadForm.ToolButtonRightClick(Sender: TObject);
begin
  RichEdit.Paragraph.Alignment:=taRightJustify;
end;

procedure TNotePadForm.EditComputerEnter(Sender: TObject);
begin
  with EditComputer do
   begin
    SelStart:=0;
    SelLength:=10000;
   end;
end;

procedure TNotePadForm.EditComputerKeyPress(Sender: TObject; var Key: Char);
const
  ConKey=['0'..'9','a'..'f','A'..'F',
          '.','h','H','d','D','o','O',
          'b','B','+','-','*','/','^',
          '!','m','M','v','V',#8];
var
  S1,S2:String;
  Oper:Char;
  I,Len:Integer;
  R:Int64;
  Ok:Boolean;
begin
  Ok:=True;
  Oper:=#0;
  R:=1;
  with EditComputer do
  begin
  case Key of
    #13:begin
        Len:=Length(Text);
        for I:=1 to Len do
          if Text[I] in ['+','-','*','/','^','M','V'] then
            Oper:=Text[I]
          else
          begin
            if Oper='' then
              S1:=S1+String(Text[I])
            else
              S2:=S2+string(Text[I]);
          end;
        if (Oper<>'') and (S2<>'') then
          case Oper of
            '+':Text:=FloatToStr(StrToFloat(S1)+StrToFloat(S2));
            '-':Text:=FloatToStr(StrToFloat(S1)-StrToFloat(S2));
            '*':Text:=FloatToStr(StrToFloat(S1)*StrToFloat(S2));
            '/':Text:=FloatToStr(StrToFloat(S1)/StrToFloat(S2));
            '^':Text:=FloatToStr(Exp(Ln(StrToFloat(S1))*StrToFloat(S2)));
            'M':Text:=IntToStr(StrToInt(S1) mod StrToInt(S2));
            'V':Text:=IntToStr(StrToInt(S1) div StrToInt(S2));
            else  Ok:=False;
          end
        else
         if Len=0 then
           Ok:=False
         else
         begin
          Oper:=s1[len];
          S1:=copy(S1,0,Len-1);
          if S1='' then
            Ok:=False
          else
            case Oper of
              'D':Text:=IntToStr(StrToInt('$'+S1));
              'H':Text:=Format('%X',[StrToInt(S1)]);
              'O':Text:=IntToHex(StrToInt(S1), 8);
              '!':begin
                    for I:=1 to StrToInt(S1) do
                      R:=R*I;
                    Text:=IntToStr(R);
                  end;
              else  Ok:=False;
            end;
        end;
        if Ok=False then
          Statusbar.Panels[0].Text:='错误的表达式'
        else
          Statusbar.Panels[0].Text:='计算完毕';
        SelStart:=10000;
        end;//with
    'p','P':SelText:=FloatToStr(Pi);
    'x','X':SelText:=FloatToStr(Exp(1.0));
  end;
  if not (key in Conkey) then
    key:=#0
  end;
end;

procedure TNotePadForm.MenuOptionKeyBoradClick(Sender: TObject);
begin
  WinExec('rundll32.exe shell32.dll,Control_RunDLL Main.cpl,键盘',1);
end;

procedure TNotePadForm.MenuHelpHowToUseClick(Sender: TObject);
begin
  Application.HelpCommand(HELP_HELPONHELP, 0);
end;

procedure TNotePadForm.MenuFunctionPlaysoundClick(Sender: TObject);
var
  MediaFileName:string;
  MediaType:string;
  TempDir: array[0..255] of Char;
begin
  with MenuFunctionPlaysound do
    Checked:=not Checked;
  if MenuFunctionPlaysound.Checked then
  begin
    with OpenDialog do
    begin
      GetWindowsDirectory(@TempDir,255);
      InitialDir:=StrPas(TempDir)+'\media';
      OpenDialog.FileName:='';
      Filter:=MediaFilter;
      if Execute then
        MediaFileName:=OpenDialog.FileName;
    end;
    if Length(MediaFileName)>0 then
    begin
      MediaType:=LowerCase(ExtractFileExt(MediaFileName));
      if MediaType='.wav'
      then
        PlaySound(PChar(MediaFileName),0,snd_Async+snd_Loop)
      else if MediaType='.mid' then
      begin
        MciSendString(Pchar('Open '+MediaFileName+' TYPE SEQUENCER ALIAS NN'),NIL,0,0);
        MciSendString(Pchar('Play nn'),NIL,0,0)
      end
      else if MediaType='.mp3' then
        ShellExecute(0,NIL,Pchar(MediaFileName),NIL,NIL,0);
    end;
  end
  else
  begin
    PlaySound(NIL,0,0);
    MciSendString('CLOSE nn',NIL,0,0);
  end;
end;

procedure TNotePadForm.RichEditSelectionChange(Sender: TObject);
begin
  UpdatePos;
end;

procedure TNotePadForm.RichEditMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (Button=mbright) and (RichEdit.SelLength=0)  then
    RichEdit.Perform(WM_LBUTTONDOWN, 0, MakeLong(X, Y));
  //按右键且无选定块则发送左键消息用于选定
end;

procedure TNotePadForm.RichEditKeyPress(Sender: TObject; var Key: Char);
var
  I:Integer;
  S:ShortString;
begin
  if Key=#13 then
  with RichEdit do
  begin
    if AutoAlign then
    begin
      i:=0;
      if Length(Lines[CaretPos.y])>0 then
      begin
        i:=1;
        while Lines[CaretPos.y][i]=' ' do
          Inc(i);
        Dec(i);
      end;
      SelText:=NewLine;s:='';
      while i>0 do
      begin
        s:=s+' ';
        Dec(i);
      end;
      SelText:=s;
      key:=#0;
    end
    else if InsertLine then
      Lines.Insert(CaretPos.y+1,'');
  end;
end; 

procedure TNotePadForm.MenuFileOpenCDROMClick(Sender: TObject);
begin
  MciSendString('Set cdaudio door open wait',nil,0,Handle);
end;

procedure TNotePadForm.MenuFileClosedCDROMClick(Sender: TObject);
begin
  MciSendString('Set cdaudio door closed wait',nil,0,Handle);
end;

procedure TNotePadForm.MenuHelpContentClick(Sender: TObject);
begin
  //ShellExecute(Handle,'open','help.txt',nil,nil,SW_ShowNormal);
  RichEdit.Lines.Add('[Delphi编程驿站]http://www.delphiesite.91i.net'+
'NotePad 2003'+#10+'朋友!您好!'+#10+'很高兴您正在使用我的作品。'+#10
+'我选择了Borland公司的产品Delphi ,'+'“NotePad 2003”是我用Delphi编制的一个Windows下的字处理应用程序。'+#10
+'目前NotePad 2003 是Delphi的1.0版,它完全可以替代Windows自带的记事本程序。'+#10
+'我会不断交流与学习过程中将其加以改进,推出后续版本的。'+#10
+'目前共享软件中已经有菜单及提示们版文ePad 2003正是在出于这样的想法而产生的。');
end;

procedure TNotePadForm.PerformRead(Sender: TObject);
begin
with MenuFunctionAutoRead do
  begin
    Checked:=not Checked;
    RichEdit.ReadOnly:=Checked;
    if Checked then
    begin
      Line:=0;
      TimerRead.Interval:=ReadSpeed;
      TimerRead.Enabled:=True;
      Statusbar.Panels[0].Text:='正在阅读中';
    end
    else
    begin
      RichEdit.SetFocus;
      TimerRead.Interval:=0;
      TimerRead.Enabled:=False;
      Statusbar.Panels[0].Text:='阅读完毕';
      if Line>=RichEdit.Lines.Count-1 then
        Application.MessageBox('阅读完毕!','阅读',MB_ICONEXCLAMATION);
    end;
  end;
end;

procedure TNotePadForm.TimerReadTimer(Sender: TObject);
begin
  with RichEdit.Lines do
    if Line<Count-1 then
    begin
      SendMessage(RichEdit.Handle, WM_VSCROLL, 1, 0);
      Inc(Line);
    end
    else
    begin
      MenuFunctionAutoReadClick(Sender);
    end;
end;

procedure TNotePadForm.MenuFunctionAutoReadClick(Sender: TObject);
begin
  TimerRead.Enabled := True;
  PerformRead(Sender);
end;

function TNotePadForm.CurrText: TTextAttributes;
begin
  if RichEdit.SelLength > 0 then Result := RichEdit.SelAttributes
  else Result := RichEdit.DefAttributes;
end;

procedure TNotePadForm.MenuEditToCapitalClick(Sender: TObject);
begin
  with RichEdit do
    if SelLength>0 then
      SelText:=LowerCase(SelText)
    else
      Text:=LowerCase(Text);
end;

procedure TNotePadForm.MenuEditToLittleClick(Sender: TObject);
begin
  with RichEdit do
    if SelLength>0 then
      SelText:=UpperCase(SelText)
    else
      Text:=UpperCase(Text);
end;

procedure TNotePadForm.FontComboBoxChange(Sender: TObject);
begin
  //FontComboBox.Items.AddStrings(Screen.Fonts);
end;

procedure TNotePadForm.ToolButtonMailClick(Sender: TObject);
begin
  with Application do
    MessageBox(Pchar('Sorry!本功能有待完善。'),Pchar(Title),MB_ICONEXCLAMATION);
end;

procedure TNotePadForm.MenuOptionSetSreenClick(Sender: TObject);
begin
  SendMessage(Handle, WM_SYSCOMMAND, SC_SCREENSAVE, 0);
end;

procedure TNotePadForm.MenuFileAttributeClick(Sender: TObject);
begin
  FormAttribute:=TFormAttribute.Create(Application);
  FormAttribute.ShowModal;
end;

procedure TNotePadForm.MenuInsertPictureClick(Sender: TObject);
var
  Picture: TPicture;
  //OpenPictureDialog: TOpenPictureDialog;
begin
  //OpenPictureDialog := TOpenPictureDialog.Create(nil);
  try
    //OpenPictureDialog.Filter := Format('%s|%s|%s', [GraphicFilter(TBitmap),
      //GraphicFilter(TMetafile),GraphicFilter(TJPEGImage)]);
    if OpenPictureDialog.Execute then
    begin
      Picture := TPicture.Create;
      try
        Picture.LoadFromFile(OpenPictureDialog.FileName);
        Clipboard.Assign(Picture);
        RichEdit.PasteFromClipboard;
      finally
        Picture.Free;
      end;
    end;
  finally
    OpenPictureDialog.Free;
  end;
end;
procedure TNotePadForm.MenuFuntionSkinClick(Sender: TObject);
begin
  OpenDialog.InitialDir := 'SkinForm';
  OpenDialog.Filter := SkinFilter;
  if OpenDialog.Execute then
     begin
       SkinData.SkinFile := OpenDialog.FileName;
     end;
end;

end.

⌨️ 快捷键说明

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