小型文本修饰器

//---------------------------------------------------------------------------

#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;//设置背景色

        }
}
//---------------------------------------------------------------------------

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值