松鼠的博客

导航

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(00, Edit1->Width, Edit1->Height));    //先清除所有的内容

    can
->Brush->Color = clBlue;
    can
->FillRect(Rect(221414));  //画上一个蓝色矩形框

    can
->Font->Color = clBlack;
    can
->Brush->Style = bsClear;
    can
->TextOut(162, Edit1->Text);  //写上文字(Edit并不知道你会自己画,所以它不会自动调整内容,所以连原来的文字也要自己画一遍)

    Editing 
= false;
  }

}

posted on 2008-12-02 10:23  Xproer-松鼠  阅读(1599)  评论(0)    收藏  举报