【问题标题】:Custom component redraw issue with DelphiDelphi 的自定义组件重绘问题
【发布时间】:2010-09-23 03:36:22
【问题描述】:

我编写了一个从 TLabel 派生的新自定义组件。该组件向组件添加了一些自定义绘图,但没有别的。绘制组件后,一切正常。但是当需要重绘时(比如在组件上拖动另一个窗口),“标签部分”工作正常,但我的自定义绘图没有正确更新。我基本上是在重写的 Paint 方法中直接绘制到画布上,当需要重绘时,我的代码绘制的画布部分被涂成黑色。似乎没有调用paint方法。我应该怎么做才能得到正确的重绘?

组件基本上是:

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。如果 Canvas 不完全可见,floodfill 会导致伪影。我删除了 Floodfill,现在它可以根据需要工作了。

【问题讨论】:

    标签: delphi drawing custom-component


    【解决方案1】:

    已解决:

    问题是(冗余)使用 FloodFill。如果 Canvas 不完全可见,floodfill 会导致伪影。我删除了 Floodfill,现在它可以根据需要工作了。

    【讨论】:

      【解决方案2】:

      我不能 100% 确定它是否适合您,但我发现通过在表单上放置 TXPManifest 可以解决渲染问题。

      【讨论】:

        【解决方案3】:

        我猜您的 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;
        

        它刷新就好了。在它周围画一个漂亮的红色框。你不是在转换积分吗?不确定是什么导致它按照您描述的方式运行。

        【讨论】:

        • 基本一样,我只是用椭圆和floodfill。我必须尝试将组件减少一点,看看是否有干扰。
        猜你喜欢
        • 1970-01-01
        • 2012-12-24
        • 1970-01-01
        • 2011-05-02
        • 2013-12-08
        • 1970-01-01
        • 2010-11-14
        • 2017-10-10
        • 2023-03-19
        相关资源
        最近更新 更多