2008-11-19 88 views
1

我写了一个派生自TLabel的新自定义组件。该组件将一些自定义绘图添加到组件,但没有其他。当组件被绘时,一切正常。但是当需要重绘时(例如在组件上拖动另一个窗口),“标签部分”工作正常,但我的自定义绘图未正确更新。我基本上是用覆盖的Paint方法直接绘制到画布上,当需要重画时,我的代码绘制的画布部分被绘成黑色。看起来好像没有调用paint方法。我应该怎样做才能正确重绘?用Delphi自定义组件重绘问题

的组件是基本上是:

TMyComponent = class(TCustomLabel, IMyInterface) 
.. 
protected 
    procedure Paint; override; 
.. 

procedure TMyComponent.Paint; 
begin 
    inherited; 
    MyCustomPaint; 
end; 

更新,涂料例程:

Position := Point(0,0); 
Radius := 15; 
FillColor := clBlue; 
BorderColor := clBlack; 
Canvas.Pen.Color := BorderColor; 
Canvas.Pen.Width := 1; 
Canvas.Brush.Color := BorderColor; 
Canvas.Ellipse(Position.X, Position.Y, Position.X + Radius, Position.Y + Radius); 
Canvas.Brush.Color := FillColor; 
Canvas.FloodFill(Position.X + Radius div 2, 
    Position.Y + Radius div 2, BorderColor, fsSurface); 

解决:

的问题是(冗余)使用FloodFill的。如果画布不完全可见,则填充会导致工件。我删除了填埋场,现在它可以根据需要运行。

回答

1

求解:

问题是(冗余)使用FloodFill。如果画布不完全可见,则填充会导致工件。我删除了填埋场,现在它可以根据需要运行。

1

我猜你的MyCustomPaint有问题,因为其余部分编码正确。这是我的MyCustomPaint的实现。告诉我什么是比你的不同:

procedure TMyComponent.MyCustomPaint; 
var 
    rect: TRect; 
begin 
    rect := self.BoundsRect; 
    rect.TopLeft := ParentToClient(rect.TopLeft); 
    rect.BottomRight := ParentToClient(Rect.BottomRight); 
    Canvas.Pen.Color := clRed; 
    Canvas.Rectangle(Rect); 
end; 

它刷新就好了。在它周围绘制一个漂亮的红色框。你可能没有转换这些观点吗?不知道什么可能会导致它按照您描述的方式行事。

+0

它基本上是一样的,我只是使用椭圆和填充。我必须尝试减少组件以查看是否存在某种干扰。 – Harriv 2008-11-20 08:30:03

0

我不是100%确定它会为你工作,但我已经看到通过将TXPManifest放置在窗体上来解决渲染问题。