它的代码
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;
答案 0 :(得分:1)
使用FillRect使用当前画笔填充矩形区域。填充区域包括矩形的顶部和左侧,但不包括底部和右侧边缘。
begin
Image1.Canvas.Brush.Style := bsSolid;
Image1.Canvas.Brush.Color := clWtite;
Image1.Canvas.FillRect(Image1.Canvas.ClipRect);
end;
答案 1 :(得分:1)
TImage
控件包含一个简单的位图。它不包含图层。这意味着您无法移除和弦并留下弦线。字符串线已经被绘制并需要重新绘制。
由于你需要重新绘制字符串线,在我看来,最简单的方法是重新绘制整个画布。我会说TImage
是这项任务的错误控制。它适用于静态图像。
对于像这样的动态图像,TPaintBox
是更好的选择。您提供了OnPaint
事件处理程序。您还必须记住需要绘制的状态。此状态将包含和弦及其指法的详细信息。当您需要重新绘制时,更新此状态并调用Invalidate
绘图框。这将强制执行一个将调用OnPaint
处理程序的绘制周期。