//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
const TColor colors[]={clRed,clGreen,clYellow,clPurple,clBlack};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Application->Title="模拟聊天室"; //应用程序在任务栏标题
Memo1->Lines->Add("欢迎进入聊天室!");
ActiveControl=Edit1; //编辑框获得焦点
Button1->Default=true; //默认按钮,按回车键触发点击该按钮
ColorBox1->Selected=clMoneyGreen;
Memo1->Color=clMoneyGreen;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Edit1->Text!="") //如果编辑框非空
{
if(CheckBox1->Checked) //如果勾选了"谁说"
{
AnsiString who;
if(RadioGroup1->ItemIndex==0)
who="【我说】:";
else if(RadioGroup1->ItemIndex==1)
who="【你说】:";
Edit1->Text=who+Edit1->Text;
}
Memo1->Lines->Add(Edit1->Text); //将编辑框的文本添加到Memo框
Edit1->Text=""; //编辑框清空
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if((Key>='a'&&Key<='z')||(Key>='A'&&Key<='Z'))
{
ShowMessage("不能输入字母");
Key=0;
}
}
//---------------------------------------------------------------------------
//试图进入Memo1使之成为焦点接受输入
void __fastcall TForm1::Memo1Enter(TObject *Sender)
{
ShowMessage("不能在这里编辑");
ActiveControl=Edit1;
}
//---------------------------------------------------------------------------
//下拉列表框选择一种文字颜色
void __fastcall TForm1::ComboBox1Select(TObject *Sender)
{
Memo1->Font->Color=colors[ComboBox1->ItemIndex];
}
//---------------------------------------------------------------------------
//颜色下拉列表框改变背景颜色
void __fastcall TForm1::ColorBox1Change(TObject *Sender)
{
Memo1->Color=ColorBox1->Selected;
}
//---------------------------------------------------------------------------