Delphi 如何在tcanvas上删除上一个映像的结果

Delphi 如何在tcanvas上删除上一个映像的结果,delphi,canvas,Delphi,Canvas,这是代码吗 procedure TForm1.SpeedButton1Click(Sender: TObject); begin SpeedButton1.Tag := SpeedButton1.Tag + 1; if SpeedButton1.Tag = 4 then SpeedButton1.Tag := 0; //------------------------------------------------------------------------------ with Image

这是代码吗

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
SpeedButton1.Tag := SpeedButton1.Tag + 1;
if SpeedButton1.Tag = 4 then
SpeedButton1.Tag := 0;
//------------------------------------------------------------------------------
with Image1.Canvas do
begin
Brush.Style := BSSolid;
Pen.Color := $0000FF;
Pen.Style := PSSolid;
Pen.Width := 5;
//------------------------------------------------------------------------------
case SpeedButton1.Tag of
0 :
Ellipse(Image1.Width - 45, 4, Image1.Width - 35, 14);
1 :
Ellipse(Image1.Width - 45, 32, Image1.Width - 35, 42);
2 :
Ellipse(Image1.Width - 115, 4, Image1.Width - 125, 14);
3 :
Ellipse(Image1.Width - 115, 32, Image1.Width - 125, 42);
end;
SpeedButton1.Caption := 'Pos : '+IntToStr(SpeedButton1.Tag);
end;
Image1.Invalidate;
{ Image1.Canvas.Refresh;
Image1.Repaint;
Image1.Refresh;
}
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoubleBuffered := true;
//------------------------------------------------------------------------------
with Image1.Canvas do
begin
Brush.Style := BSClear;
Pen.Color := $000000;
Pen.Style := PSSolid;
//------------------------------------------------------------------------------
Pen.Width := 5;
MoveTo(Image1.Width - 2, 6);
LineTo(Image1.Width - 2, 40);
//------------------------------------------------------------------------------
Pen.Width := 2;
MoveTo(Image1.Width - 80, 6);
LineTo(Image1.Width - 80, 40);
MoveTo(Image1.Width - 160, 6);
LineTo(Image1.Width - 160, 40);
MoveTo(Image1.Width - 240, 6);
LineTo(Image1.Width - 240, 40);
MoveTo(Image1.Width - 320, 6);
LineTo(Image1.Width - 320, 40);
//------------------------------------------------------------------------------
Pen.Width := 1;
MoveTo(0, 8);
LineTo(Image1.Width, 8);
MoveTo(0, 38);
LineTo(Image1.Width, 38);
//------------------------------------------------------------------------------
Brush.Style := BSSolid;
Pen.Color := $0000FF;
Pen.Style := PSSolid;
//------------------------------------------------------------------------------
Pen.Width := 5;
Ellipse(Image1.Width - 45, 4, Image1.Width - 35, 14);
end;
Image1.Invalidate;
end;

使用FillRect使用当前笔刷填充矩形区域。将填充该区域,包括矩形的顶部和左侧,但不包括底部和右侧边缘

begin
  Image1.Canvas.Brush.Style := bsSolid;
  Image1.Canvas.Brush.Color := clWtite;
  Image1.Canvas.FillRect(Image1.Canvas.ClipRect);
end;

TImage
控件保存一个简单的位图。它不包含层。这意味着您不能删除和弦并保留弦线。字符串线已绘制完毕,需要重新绘制

因为你需要重新画线,在我看来,重新画整个画布是最简单的。我认为
TImage
是此任务的错误控件。它适用于静态图像


对于这样的动态图像,
tpainbox
是更好的选择。您提供了一个
OnPaint
事件处理程序。您还必须记住需要绘制的状态。此状态将包含和弦及其指法的详细信息。当您需要重新绘制时,更新此状态并调用
Invalidate
绘制框。这将强制执行绘制循环,该循环将调用
OnPaint
处理程序

我的意思是:如何删除图片中的和弦[C],当按下和弦[D]画布上的按钮时,只显示图像和弦[D]。对不起,我的英语不好。你可能应该在这里使用TPaintBox。您不需要持久映像。TImage专为静态图像设计。我从未使用TPaintBox,但我无法在TPaintBox上的OnPaint程序外更新画布上的椭圆,例如:我无法使用按钮更新新椭圆。请给我一个简单的例子来说明你的意思。谢谢这里有很多使用
tpainbox
的例子。我相信Embarcadero提供了一些。我相信你可以通过网络搜索找到它们,而不是我搜索它们并指向它们。