【发布时间】:2018-09-03 07:04:11
【问题描述】:
我有一个想要清除的TPaintBox。但我仍然需要透明度,所以画一个矩形是不可能的。如何清除?
【问题讨论】:
-
什么类型的画布? VCL
TCanvas没有透明度。这通常由透明颜色处理,通常是白色。
我有一个想要清除的TPaintBox。但我仍然需要透明度,所以画一个矩形是不可能的。如何清除?
【问题讨论】:
TCanvas 没有透明度。这通常由透明颜色处理,通常是白色。
请注意,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;
【讨论】: