MemoControl.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:2k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "MemoControl.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->OpenDialog1->Filter="All Files(*.*)|*.*|Text Files(*.txt)|*.txt";
- //设置文件过滤条件
- Form1->OpenDialog1->DefaultExt=String("TXT");
- //设置缺省扩展名
- Form1->SaveDialog1->Title="请选择一个文本文件:";
- //设置对话框标题
- Form1->SaveDialog1->Filter="All Files(*.*)|*.*|Text Files(*.txt)|*.txt";
- //设置文件过滤条件
- Form1->SaveDialog1->DefaultExt=String("TXT");
- //设置缺省扩展名
- Form1->Button2->Enabled=false;
- //设置按钮有效状态
- Form1->FontDialog1->Font=Form1->Memo1->Font;
- Form1->ColorDialog1->Color=Form1->Memo1->Color;
- //对话框的初始化
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- if (Form1->OpenDialog1->Execute())
- //打开一个对话框
- {
- Form1->Memo1->Lines->LoadFromFile(Form1->OpenDialog1->FileName);
- //打开一个文件
- Form1->Button2->Enabled=true;
- //设置按钮有效状态
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- if (Form1->SaveDialog1->Execute())
- //显示一个对话框
- {
- Form1->Memo1->Lines->SaveToFile(Form1->SaveDialog1->FileName);
- //保存文件
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- if (Form1->FontDialog1->Execute())
- //打开一个对话框
- {
- Form1->Memo1->Font=Form1->FontDialog1->Font;
- //设置控件中文本显示字体
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- if (Form1->ColorDialog1->Execute())
- //打开一个对话框
- {
- Form1->Memo1->Color=Form1->ColorDialog1->Color;
- //设置控件背景色
- }
- }
- //---------------------------------------------------------------------------