自定义组件画图残影问题
我有一个自定义的组件,背景是透明的,在组件上用TPicture画一个幅含alpha通过的Png图片。
组件有一个drawstyle属性,值可为Normal、Stretch、和Tile三种。
我在DrawStyle属性的SetDrawStyle方法最后调用了,Repaint方法。可是在切换DrawStyle属性值是,会有图片残影,非得用鼠标点一下组件,才正常,该怎么解决?
下边是Paint方法代码:
void __fastcall TJTImagePanel::Paint(){ //画图片 if(FPicture->Graphic != NULL) { //FPicture->Graphic-> if(FDrawStyle == jtStretch) Canvas->StretchDraw(ClientRect,FPicture->Graphic); else if(FDrawStyle == jtTile) TileDraw(Canvas,FPicture,ClientRect); else Canvas->Draw(0,0,FPicture->Graphic); } //画文字 int FontHeight; int Flags; TRect Rect = GetClientRect(); if (Fborder || ComponentState.Contains(csDesigning)) { Canvas->Brush->Color = clBtnShadow; Canvas->FrameRect(Rect); } Canvas->Brush->Style = bsClear; Canvas->Font = Font; FontHeight = Canvas->TextHeight('W'); Rect.Top = ((Rect.Bottom + Rect.Top) - FontHeight) / 2; Rect.Bottom = Rect.Top + FontHeight; Flags = DT_EXPANDTABS | DT_VCENTER | DT_CENTER; Flags = DrawTextBiDiModeFlags(Flags); DrawText(Canvas->Handle, Caption.t_str(), -1, &Rect, Flags); TCustomControl:: Paint();}void __fastcall TJTImagePanel::SetDrawStyle(const TJTDrawStyle style){ FDrawStyle = style; Repaint(); }
Canvas->Brush->Style =bsClear; Canvas->FillRect(Rect)