views:

665

answers:

4

I have written a new custom component derived from TLabel. The component adds some custom drawing to component, but nothing else. When component is painted, everything works fine. But when the redraw is needed (like dragging another window over the component), "label part" works fine but my custom drawing is not properly updated. I'm basically drawing directly to the canvas in an overridden Paint method, and when the redraw is required the parts of canvas where my code has drawn something is painted black. It seems like that the paint method is not called. What I should do to get proper redraw?

The component is basically:

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

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

Update, the paint routine:

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);

SOLVED:

The problem is (redundant) use of FloodFill. If the Canvas is not fully visible floodfill causes artifacts. I removed the floodfill and now it works as needed.

+1  A: 

I am guessing there is something wrong in your MyCustomPaint because the rest is coded correctly. Here is my implementation of a MyCustomPaint. Tell me what is different than yours:

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;

It refreshes just fine. Draws a nice red box around it. Are you not converting the points maybe? Not sure what could cause it to behave the way you described.

Jim McKeeth
It's basically same, I'm just using ellipse and floodfill. I've to try to reduce the component a bit to see if there's something interferencing.
Harriv
A: 

Are you using windows Vista? There are some additional codes for vista glass thing in controls in >=delphi2007. It can be a bug related with that.

AhmetC
A: 

I am not 100% sure it'll work for you, but I've seen rendering problem getting fixed by placing TXPManifest on a form.

eed3si9n
A: 

SOLVED:

The problem is (redundant) use of FloodFill. If the Canvas is not fully visible floodfill causes artifacts. I removed the floodfill and now it works as needed.

Harriv