代码之家  ›  专栏  ›  技术社区  ›  Harriv

使用Delphi自定义组件重画问题

  •  1
  • Harriv  · 技术社区  · 17 年前

    该部分基本上是:

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

    解决了的:

    问题是(冗余)使用洪水填充。如果画布不完全可见,泛光填充会导致瑕疵。我现在移除了需要的洪水。

    3 回复  |  直到 17 年前
        1
  •  1
  •   Jim McKeeth    17 年前

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

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

        2
  •  1
  •   Harriv    17 年前

    解决了的:

        3
  •  0
  •   Eugene Yokota    17 年前

    我不是100%确定它是否适合您,但我看到通过放置 TXPManifest 在表格上。