Edit 控件自绘
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if ((Key == 13)&&(Editing)) //Key=13表示回车键
{
hDC = ::GetDC(Edit1->Handle); //取得Edit1的DC(设备上下文,画图用的)
can->Handle = hDC; //并把它连到一个canvas上,现在can就相当于Edit1的画布,可以随意作画。
can->Brush->Color = clWhite;
can->Brush->Style = bsSolid;
can->FillRect(Rect(0, 0, Edit1->Width, Edit1->Height)); //先清除所有的内容
can->Brush->Color = clBlue;
can->FillRect(Rect(2, 2, 14, 14)); //画上一个蓝色矩形框
can->Font->Color = clBlack;
can->Brush->Style = bsClear;
can->TextOut(16, 2, Edit1->Text); //写上文字(Edit并不知道你会自己画,所以它不会自动调整内容,所以连原来的文字也要自己画一遍)
Editing = false;
}
}



浙公网安备 33010602011771号