Individual problem with reworking components with Delphi
I wrote a new custom component derived from TLabel. The component adds some custom drawing to the component, but nothing else. When the component gets colored, everything works fine. But when there is a need to redraw (like dragging another window over a component) the "label" works fine, but my custom drawing doesn't update as expected. I mostly paint directly to the canvas in an overridden Paint method, and when redrawing is required, the parts of the canvas where my code painted something are colored black. It looks like the paint method is not named. What should I do to redraw correctly?
The component is basically:
TMyComponent = class(TCustomLabel, IMyInterface)
..
protected
procedure Paint; override;
..
procedure TMyComponent.Paint;
begin
inherited;
MyCustomPaint;
end;
Update, handmade:
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);
DECIDE:
The problem is (over) using FloodFill. If the Canvas is not fully visible, the flood is causing artifacts. I removed the fill and now it works as needed.
source to share
I am guessing that there is something wrong in your MyCustomPaint because the rest are being encoded correctly. Here is my implementation of MyCustomPaint. Tell me what is different from 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 perfectly. Draws a beautiful red box around it. Could you transfer points? Not sure what could make it behave the way you described.
source to share