【问题标题】:Is it possible to clear a TPaintBox without drawing over with a rectangle是否可以在不绘制矩形的情况下清除 TPaintBox
【发布时间】:2018-09-03 07:04:11
【问题描述】:

我有一个想要清除的TPaintBox。但我仍然需要透明度,所以画一个矩形是不可能的。如何清除?

【问题讨论】:

  • 什么类型的画布? VCL TCanvas 没有透明度。这通常由透明颜色处理,通常是白色。

标签: delphi canvas


【解决方案1】:

请注意,TPaintBox 没有透明的概念。为了给人一种透明的印象,您可以防止在您想要显示的区域进行绘画(显示TPaintBox 后面的内容)。

在下面的示例中,我有一个带有风景图片的TImage。最重要的是,有一个TPaintBox 绘制了红线的十字。使用Button1,我切换boolean 标志(TimeToClear)并调用PaintBox1.Invalidate;

OnPaint 方法:

procedure TForm26.PaintBox1Paint(Sender: TObject);
begin
// Simply exit to prevent any painting;
  if TimeToClear then Exit;

// Otherwise perform normal drawing
  with (Sender as TPaintBox).Canvas do
  begin
    Pen.Style := psSolid;
    Pen.Color := Vcl.Graphics.clRed;
    Pen.Width := 5;
    MoveTo(  0,  0);
    LineTo(105,105);
    MoveTo(105,  0);
    LineTo(  0,105);
  end;
end;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2015-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 2014-08-29
    相关资源
    最近更新 更多