![]() |
用C++Builder設計記事本
表單
![]() 程式碼(Unit.cpp) //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <Clipbrd.hpp> //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; TTabSheet* pts[128]; TRichEdit* rich[128]; int PageNo=0; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { ListBox1->Items->Add(Clipboard()->AsText); pts[PageNo]=new TTabSheet(this); pts[PageNo]->PageControl=PageControl1; pts[PageNo]->Caption="NewText - "+IntToStr(PageNo)+".txt"; rich[PageNo]=new TRichEdit(this); rich[PageNo]->Parent=pts[PageNo]; rich[PageNo]->Align=alClient; rich[PageNo]->ScrollBars=ssBoth; rich[PageNo]->Font->Name="Fixedsys"; rich[PageNo]->PlainText=true; rich[PageNo]->OnKeyPress=rich_KeyPress; PageControl1->ActivePage=pts[PageNo]; PageNo++; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton1Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton1->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton2Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton2->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton3Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton3->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton4Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton4->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton5Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton5->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton6Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton6->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton7Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton7->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton8Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText="「"+rich[PageControl1->ActivePageIndex]->SelText+"」"; rich[PageControl1->ActivePageIndex]->SelStart=rich[PageControl1->ActivePageIndex]->SelStart-2; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton9Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText="『"+rich[PageControl1->ActivePageIndex]->SelText+"』"; rich[PageControl1->ActivePageIndex]->SelStart=rich[PageControl1->ActivePageIndex]->SelStart-2; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton10Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText="("+rich[PageControl1->ActivePageIndex]->SelText+")"; rich[PageControl1->ActivePageIndex]->SelStart=rich[PageControl1->ActivePageIndex]->SelStart-2; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton11Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText="【"+rich[PageControl1->ActivePageIndex]->SelText+"】"; rich[PageControl1->ActivePageIndex]->SelStart=rich[PageControl1->ActivePageIndex]->SelStart-2; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton12Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=SpeedButton12->Caption; } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton1Click(TObject *Sender) { pts[PageNo]=new TTabSheet(this); pts[PageNo]->PageControl=PageControl1; pts[PageNo]->Caption="NewText - "+IntToStr(PageNo)+".txt"; rich[PageNo]=new TRichEdit(this); rich[PageNo]->Parent=pts[PageNo]; rich[PageNo]->Align=alClient; rich[PageNo]->ScrollBars=ssBoth; rich[PageNo]->Font->Name="Fixedsys"; rich[PageNo]->PlainText=true; rich[PageNo]->OnKeyPress=rich_KeyPress; PageControl1->ActivePage=pts[PageNo]; PageNo++; } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton2Click(TObject *Sender) { if(OpenDialog1->Execute()){ rich[PageControl1->ActivePageIndex]->Lines->LoadFromFile(OpenDialog1->FileName); rich[PageControl1->ActivePageIndex]->Hint=OpenDialog1->FileName; } } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton3Click(TObject *Sender) { SaveDialog1->FileName=PageControl1->ActivePage->Caption; SaveDialog1->InitialDir=rich[PageControl1->ActivePageIndex]->Hint; if(SaveDialog1->Execute()){ rich[PageControl1->ActivePageIndex]->Lines->SaveToFile(SaveDialog1->FileName); } } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton5Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->CutToClipboard(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton6Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->CopyToClipboard(); } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton7Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->PasteFromClipboard(); } //--------------------------------------------------------------------------- void __fastcall TForm1::N21231Click(TObject *Sender) { pts[PageNo]=new TTabSheet(this); pts[PageNo]->PageControl=PageControl1; rich[PageNo]=new TRichEdit(this); rich[PageNo]->Parent=pts[PageNo]; rich[PageNo]->Align=alClient; rich[PageNo]->ScrollBars=ssBoth; rich[PageNo]->Font->Name="Fixedsys"; rich[PageNo]->PlainText=true; rich[PageNo]->OnKeyPress=rich_KeyPress; PageControl1->ActivePage=pts[PageNo]; rich[PageNo]->PasteFromClipboard(); pts[PageNo]->Caption=rich[PageNo]->Lines->Strings[0]+".txt"; PageNo++; } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton8Click(TObject *Sender) { ListBox1->Items->Add(rich[PageControl1->ActivePageIndex]->SelText); } //--------------------------------------------------------------------------- void __fastcall TForm1::ToolButton9Click(TObject *Sender) { ListBox1->Items->Delete(ListBox1->ItemIndex); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) { for(int i=0;i<PageNo;i++){ delete rich[i]; delete pts[i]; } } //--------------------------------------------------------------------------- void __fastcall TForm1::ListBox1Click(TObject *Sender) { rich[PageControl1->ActivePageIndex]->SelText=ListBox1->Items->Strings[ListBox1->ItemIndex]; } //--------------------------------------------------------------------------- void __fastcall TForm1::rich_KeyPress(TObject *Sender, char &Key) { if (Key == 13 && PageControl1->ActivePage->Caption == "NewText - "+IntToStr(PageControl1->ActivePageIndex)+".txt" && rich[PageControl1->ActivePageIndex]->Lines->Count > 0) { PageControl1->ActivePage->Caption=rich[PageControl1->ActivePageIndex]->Lines->Strings[0]+".txt"; } } //--------------------------------------------------------------------------- 原始檔(Password:slime) http://home.pchome.com.tw/hot/quanho.../WinEditor.exe <敬請批評指教> |
所有時間均為台北時間。現在的時間是 11:17 AM。 |
Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.
『服務條款』
* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *