以下代码是用画布做的,是画椭圆、直线和矩形
希望我的回答对你有帮组!
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
st.X:=x;
st.Y:=y;
et:=st;
cp:=true;
with image1.canvas do
begin
pen.Mode:=pmnot;
pen.Color:=clblue;
brush.Style:=bsclear;
end;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if cp then
case shapekind of
1:
begin
image1.Canvas.Ellipse(st.X,st.Y,et.x,et.y);
image1.Canvas.Ellipse(st.X,st.Y,x,y);
end;
2:
with image1.Canvas do
begin
MoveTo(st.X,st.y);
LineTo(et.x,et.y); //画的过程中能看到线
MoveTo(st.X,st.y);
LineTo(x,y);
end;
3:
begin
image1.Canvas.rectangle(st.X,st.Y,et.x,et.y);
image1.Canvas.rectangle(st.X,st.Y,x,y);
end;
end;
et.X:=x; //不写会看到移动的轨迹
et.Y:=y;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
cp:=false;
with image1.Canvas do
begin
pen.Mode:=pmcopy;
//pen.Width:=3;
pen.Color:=clred;
brush.Color:=clgreen;
brush.Style:=bsdiagcross;
case shapekind of
1: begin //画椭圆
//image1.Canvas.Ellipse(st.X,st.Y,et.x,et.y);
image1.Canvas.Ellipse(st.X,st.Y,x,y);
end;
2: begin //画直线
moveto(st.X,st.y);
lineto(et.X,et.y);
moveto(st.X ,st.y);
lineto(x,y);
end;
3: begin //画矩形
image1.Canvas.rectangle(st.X,st.Y,et.x,et.y);
image1.Canvas.rectangle(st.X,st.Y,x,y);
end;
end;
end;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
case radiogroup1.itemindex of
0:shapekind:=1;
1:shapekind:=2;
2:shapekind:=3;
end;
end;