如何画一个小小圆,圆里面填充红色(50分)

  • 主题发起人 主题发起人 天空4567
  • 开始时间 开始时间

天空4567

Unregistered / Unconfirmed
GUEST, unregistred user!
1、窗体上有10个Image控件,想以此在循环中画10个小圆,并同时填充红色,怎么画?
2、每循环一次,画一个相应位置的圆并填充红色,而Image控件是从Image1到
Image10,如果循环变量n:=1 to 9,想用n来控制各Image控件,可行吗?怎么做?
 
var
tmpImage: TImage;
begin
for i := 1 to 9 do
begin
tmpImage := TImage(FindComponent(Format('Image%d', )));
tmpImage.Canvas.Brush.Color := clRed;
tmpImage.Canvas.Pie(...);
{ tmpImage.Canvas.Ellipse(X1, Y1, X2, Y2); }
.....
end;
end;
 
var i:integer;
for i:=1 to 9 do
begin
with Timage(TComponent(FindComponent('image'+inttostr(i)))) do
begin
Canvas.Brush.Color:=clRed;
Canvas.Ellipse(0,0,100,100);
end;
end;
 
谢谢楼上二位。
在 with Timage(TComponent(FindComponent('image'+inttostr(i)))) do
这句时,便宜出错,说:
Undeclared identifier 'FindComponent'.
该怎么办?
 
FindComponent to determine whether a given component is owned by another.
即控件必须为其父控件所有。
应用 form1.FindComponent('image'+inttostr(i))
 
还可以用指针,定义一个指针Pimg:array[0..9]of ^TImage;然后在FormCreate中加上Pimg[0]:=@Image1;.....另外还给你简单的方法实现你的效果,放两个Image,让他们不可视,分别放不同状态的两张图。在onclick事件中让Pimg[n].Picture.BitMap:=不可见的Image的Bitmap
 
建议使用shape控件,可以设置为圆形并可以填充颜色
 
TO 张飞2002:
你说得对。
但image控件都是在FORM1中自定义的,在
with Timage(TComponent(FindComponent('image'+inttostr(i)))) do
or:tmpImage := TImage(FindComponent(Format('Image%d', )));
上述语句中,怎么添加form1呢?
 
var i:integer;
with form1 do
begin
for i:=1 to 9 do
begin
with Timage(TComponent(FindComponent('image'+inttostr(i)))) do
begin
Canvas.Brush.Color:=clRed;
Canvas.Ellipse(0,0,100,100);
end;
end;
end;
 
TO zywcd,:
谢谢你。
Canvas.Brush.Color:=clRed; //?为什么画出来的图是白色呢?
Canvas.Ellipse(0,0,100,100); //?画出来的图形为何是矩形呢?
 
Draws the ellipse defined by a bounding rectangle on the canvas.

Delphi syntax:

procedure Ellipse(X1, Y1, X2, Y2: Integer); overload;
procedure Ellipse(const Rect: TRect); overload;

C++ syntax:

void __fastcall Ellipse(int X1, int Y1, int X2, int Y2);
void __fastcall Ellipse(TRect Rect);

Description

Call Ellipse to draw a circle or ellipse on the canvas. Specify the bounding rectangle either by giving

The top left point at pixel coordinates (X1, Y1) and the bottom right point at (X2, Y2).
A TRect value.

If the bounding rectangle is a square, a circle is drawn.

The ellipse is outlined using the value of Pen, and filled using the value of Brush.

Note: On Windows 9x or Windows ME, the sums X1 + X2 and Y1 + Y2 cannot exceed 32768. Also, the sum X1 + X2 + Y1 + Y2 cannot exceed 32768.
 
谢谢楼上的。
太高深的东西我不懂。
我只想画个红色的圆,该怎么画?
 
procedure TForm1.FormPaint(Sender: TObject);
begin
Form1.Canvas.Brush.Color:= clRed;
Form1.Canvas.Ellipse(20,50,40,70);
end;
 
楼上各位:
Form1.Canvas.Brush.Color:= clRed;
Form1.Canvas.Ellipse(20,50,40,70);
这样的代码在我的代码里好象不起任何作用,第一句我的画笔没变成红色;
第二句我画的图是个矩形。
我只想画个红色的圆。
是哪里的问题?
 
楼上贴英文的那位贴的是Delphi帮助,并不高深,楼主可以看看。
 
定义一个指针Pimg:array[0..9]of ^TImage;然后在FormCreate中加上Pimg[0]:=@Image1;.....另外还给你简单的方法实现你的效果,放两个Image,让他们不可视,分别放不同状态的两张图。在onclick事件中让Pimg[n].Picture.BitMap:=不可见的Image的Bitmap 这样更复杂
 
说了许多了,可还是没人给我指出问题所在。
相同的代码在别的地方可以画彩色的圆,为何在这里却不行,
我只想知道原因,大家却让我这个哪个地..........
有对画图有特别经验的高手吗?请帮忙·!!!!!
 
我试过了,可以画出来
 
我的画不出红色圆来,是什么原因?
 
是坐标的定义及图象大小的问题。现在已经解决了。谢谢路上各位。结贴。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部