使用canvas时遇到的问题(20分)

  • 主题发起人 主题发起人 ykjt
  • 开始时间 开始时间
Y

ykjt

Unregistered / Unconfirmed
GUEST, unregistred user!
使用canvas时遇到的
procedure TForm1.Button1Click(Sender: TObject);
var
p:trect;
begin
p.Left:=image1.Left;
p.Top:=image1.Top;
p.Right:=image1.Width;
p.Bottom:=image1.Height;
edit1.Text:=inttostr(p.Right);
canvas.Brush.Style:= bsfdiagonal;
canvas.Brush.Color:=$0032bb22;
canvas.FillRect(p);
end;
本想覆盖整个image1,结果却覆盖了四分之一,是何原因?
 
最后一句差了一个对象,应为:

image1.canvas.FillRect(p);
 
procedure TForm1.Button1Click(Sender: TObject);
var
p:trect;
begin
p.Left:=image1.Left;
p.Top:=image1.Top;
p.Right:=image1.Left+image1.Width;
p.Bottom:=image1.Top+image1.Height;
edit1.Text:=inttostr(p.Right);
canvas.Brush.Style:= bsfdiagonal;
canvas.Brush.Color:=$0032bb22;
canvas.FillRect(p);
end;
 
不行,出错
 
p的位置是相对于窗体的
p.Left :=0;
p.Top :=0;
p.Right:=image1.Width;
p.Bottom:=image1.Height;
edit1.Text:=inttostr(p.Right);
canvas.Brush.Style:= bsfdiagonal;
canvas.Brush.Color:=$0032bb22;
canvas.FillRect(p);

运行一下就知道了
自己该程序吧,不难。
 
p.Left:=image1.Left;
p.Top:=image1.Top;
//p.Left :=0;
//p.Top :=0;
p.Right:=image1.Width+image1.Left;;
p.Bottom:=image1.Height+image1.Top;;
edit1.Text:=inttostr(p.Right);
canvas.Brush.Style:= bsfdiagonal;
canvas.Brush.Color:=$0032bb22;
canvas.FillRect(p);
这样就行了
 
hongxing_dl的是对的
 
weichao9999也对
 

Similar threads

后退
顶部