//---------------------------------------------------------------------------
#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::FormCreate(TObject *Sender)
{
Form1->Memo1->Clear();//清空文本框
Form1->OpenDialog1->Title="打开一个文件";
Form1->OpenDialog1->InitialDir="c://PWin98";// 设置缺省路径
Form1->OpenDialog1->Filter="ALL Files(*.*)|*.*|Text Files(*.txt)|*.txt";//设置过滤条件
Form1->OpenDialog1->DefaultExt=String("TXT");//能打开文件的属性
Form1->SaveDialog1->Title="打开一个文件";//与opendialog控件一致
Form1->SaveDialog1->InitialDir="c://PWin98";
Form1->SaveDialog1->Filter="ALL Files(*.*)|*.*|Text Files(*.txt)|*.txt";
Form1->SaveDialog1->DefaultExt=String("TXT");//设置保存文件的扩展名
Form1->FontDialog1->Font=Form1->Memo1->Font;
Form1->ColorDialog1->Color=Form1->Memo1->Color;//颜色设置
Form1->Button2->Enabled=false;//设置按键的有效性
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Form1->OpenDialog1->Execute())//打开windows环境下一个对话框
{
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;//设置背景色
}
}
//---------------------------------------------------------------------------