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

📄 unit1.cpp

📁 <<C++Builder 6实用编程100例>>随书光盘
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::OpenClick(TObject *Sender)
{
        if(OpenDialog1->Execute())
                RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);                
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ExitClick(TObject *Sender)
{
        Form1->Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FindClick(TObject *Sender)
{
        FindDialog1->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FindDialog1Find(TObject *Sender)
{
        int FoundAt,StartPos,ToEnd;
        if(RichEdit1->SelLength)
                StartPos=RichEdit1->SelStart+RichEdit1->SelLength;
        else
                StartPos=0;
        ToEnd=RichEdit1->Text.Length()-StartPos;
        FoundAt=RichEdit1->FindText(FindDialog1->FindText,StartPos,
                        ToEnd,TSearchTypes()<<stMatchCase);
        if(FoundAt!=-1)
        {
                RichEdit1->SetFocus();
                RichEdit1->SelStart=FoundAt;
                RichEdit1->SelLength=FindDialog1->FindText.Length();
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ReplaceClick(TObject *Sender)
{
        ReplaceDialog1->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ReplaceDialog1Find(TObject *Sender)
{
        int FoundAt,StartPos,ToEnd;
        if(RichEdit1->SelLength)
                StartPos=RichEdit1->SelStart+RichEdit1->SelLength;
        else
                StartPos=0;
        ToEnd=RichEdit1->Text.Length()-StartPos;
        FoundAt=RichEdit1->FindText(ReplaceDialog1->FindText,StartPos,
                        ToEnd,TSearchTypes()<<stMatchCase);
        if(FoundAt!=-1)
        {
                RichEdit1->SetFocus();
                RichEdit1->SelStart=FoundAt;
                RichEdit1->SelLength=ReplaceDialog1->FindText.Length();
        }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender)
{
        TReplaceDialog *dlg=(TReplaceDialog*)Sender;
        int SelPos;
        SelPos=RichEdit1->FindText(ReplaceDialog1->FindText,0,
                        RichEdit1->Text.Length(),TSearchTypes()<<stMatchCase);
        if(SelPos>0)
        {
                RichEdit1->SelStart=SelPos;
                RichEdit1->SelLength=dlg->FindText.Length();
                RichEdit1->SelText=dlg->ReplaceText;
        }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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