📄 text.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Text.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Form1->Memo1->Clear();
//清空文本框
Form1->OpenDialog1->Title="请选择一个文本文件:";
Form1->SaveDialog1->Title="请选择一个文本文件:";
//设置对话框的标题
Form1->OpenDialog1->Filter="Text Files(*.txt)|*.txt";
Form1->SaveDialog1->Filter="Text Files(*.txt)|*.txt";
//设置文件过滤器
Form1->OpenDialog1->DefaultExt="txt";
Form1->SaveDialog1->DefaultExt="txt";
//设置缺省文件扩展名
}
//---------------------------------------------------------------------------
void __fastcall TForm1::New1Click(TObject *Sender)
{
Form1->Memo1->Clear();
//清空文本框
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Open1Click(TObject *Sender)
{
if (Form1->OpenDialog1->Execute())
//打开一个对话框
{
Form1->Memo1->Lines->LoadFromFile(Form1->OpenDialog1->FileName);
//打开文本文件
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Save1Click(TObject *Sender)
{
if (Form1->SaveDialog1->Execute())
//打开一个对话框
{
Form1->Memo1->Lines->SaveToFile(Form1->SaveDialog1->FileName);
//存储到文本文件中
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Exit2Click(TObject *Sender)
{
if (Form1->Memo1->Modified)
//判断文件是否被改变
{
if (MessageDlg("文件已经被修改过,存储修改后的结果吗?", mtConfirmation,
TMsgDlgButtons()<< mbYes << mbNo, 0) == mrYes)
//提示用户是否保存修改结果
{
if (Form1->SaveDialog1->Execute())
//显示对话框
{
Form1->Memo1->Lines->SaveToFile(Form1->SaveDialog1->FileName);
//存储文件
}
}
}
Form1->Close();
//结束程序的运行
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Cut1Click(TObject *Sender)
{
if (Form1->Memo1->SelText!="")
//如果选中了文本内容
{
Form1->Memo1->CutToClipboard();
//将选中的数据剪切到剪贴板上
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Copy1Click(TObject *Sender)
{
if (Form1->Memo1->SelText!="")
//如果选中了文本内容
{
Form1->Memo1->CopyToClipboard();
//将选中的数据复制到剪贴板上
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Paste1Click(TObject *Sender)
{
Form1->Memo1->PasteFromClipboard();
//将当前剪贴板上的数据粘贴到当前位置上
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Delete1Click(TObject *Sender)
{
Form1->Memo1->ClearSelection();
//清除当前选中的数据
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SelectAll1Click(TObject *Sender)
{
Form1->Memo1->SelectAll();
//选中控件上的全部数据
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Left1Click(TObject *Sender)
{
Form1->Memo1->Alignment=taLeftJustify;
//设置文本左对齐方式
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Center1Click(TObject *Sender)
{
Form1->Memo1->Alignment=taCenter;
//设置文本居中对齐
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Right1Click(TObject *Sender)
{
Form1->Memo1->Alignment=taRightJustify;
//设置文本右对齐方式
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Bold1Click(TObject *Sender)
{
Form1->Bold1->Checked=! Form1->Bold1->Checked;
//设置复选状态
if (Form1->Bold1->Checked)
//如果选中黑体
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style<<fsBold;
//当前文本框中的文本以黑体的形式显示
else
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style>>fsBold;
//当前文本框中的文本不以黑体的形式显示
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Italic1Click(TObject *Sender)
{
Form1->Italic1->Checked=! Form1->Italic1->Checked;
//设置复选状态
if (Form1->Italic1->Checked)
//如果选中斜体
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style<<fsItalic;
//当前文本框中的文本以斜体的形式显示
else
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style>>fsItalic;
//当前文本框中的文本不以斜体的形式显示
}
//---------------------------------------------------------------------------
void __fastcall TForm1::UnderLine1Click(TObject *Sender)
{
Form1->UnderLine1->Checked=! Form1->UnderLine1->Checked;
//设置复选状态
if (Form1->UnderLine1->Checked)
//如果选中下划线
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style<<fsUnderline;
//当前文本框中的文本以下划线的形式显示
else
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style>>fsUnderline;
//当前文本框中的文本不以下划线的形式显示
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StrikeOut1Click(TObject *Sender)
{
Form1->StrikeOut1->Checked=! Form1->StrikeOut1->Checked;
//设置复选状态
if (Form1->UnderLine1->Checked)
//如果选中删除线
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style<<fsStrikeOut;
//当前文本框中的文本以删除线的形式显示
else
Form1->Memo1->Font->Style=Form1->Memo1->Font->Style>>fsStrikeOut;
//当前文本框中的文本不以删除线的形式显示
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -