delphi鼠标画图问题
鼠标在image控件某一点点击,在鼠标所在位置绘制一个黄色或者红色的圆形~~怎样实现.请赐教!...
鼠标在image控件某一点点击,在鼠标所在位置绘制一个黄色或者红色的圆形~~怎样实现.请赐教!
展开
4个回答
展开全部
//在界面上放置一个Image控件,MouseDown事件内写。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
procedure DrawRound(Canvas: TCanvas; Cl :TColor; vX,vY: integer);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DrawRound(Canvas: TCanvas; Cl: TColor; vX, vY: integer);
procedure circle(Canvas: TCanvas;Cl: TColor; x0,y0,x,y:integer);
begin
with Canvas do
begin
pen.Color:=Cl;
brush.Color:=Cl;
brush.color:=Cl;
pixels[x0+x,y0+y]:=Cl;
pixels[x0+x,y0-y]:=Cl;
pixels[x0-x,y0-y]:=Cl;
pixels[x0-x,y0+y]:=Cl;
end;
end;
var
x0,y0,x,y,a,b:integer;
d1,d2:real;
begin
x0:=vX;
y0:=vY;
a:=10; b:=10; x:=0; y:=b;//a,b是宽高,自己调整
d1:=b*b+a*a*(-b+0.25);
circle(Canvas,CL,x0,y0,x,y);
while(b*b*(x+1)<a*a*(y-0.5))do
if(d1<0) then
begin
d1:=d1+b*b*(2*x+3);
x:=x+1;
circle(Canvas,CL,x0,y0,x,y);
end
else
begin
d1:=d1+b*b*(2*x+3)+a*a*(-2*y+2);
x:=x+1;
y:=y-1;
circle(Canvas,CL,x0,y0,x,y);
end;
circle(Canvas,CL,x0,y0,x,y);
d2:=sqr(b*(x+0.5))+sqr(a*(y-1))-sqr(a*b);
circle(Canvas,CL,x0,y0,x,y);
while (y>0)do
if(d2<0)then
begin
d2:=d2+b*b*(2*x+2)+a*a*(-2*y+3);
x:=x+1;
y:=y-1;
circle(Canvas,CL,x0,y0,x,y);
end
else
begin
d2:=d2+a*a*(-2*y+3);
y:=y-1;
circle(Canvas,CL,x0,y0,x,y);
end;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//DrawRound(Image1.Canvas,ClRed,X,Y);//这里有红色和黄色,自己调整
DrawRound(Image1.Canvas,ClYellow,X,Y);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
procedure DrawRound(Canvas: TCanvas; Cl :TColor; vX,vY: integer);
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DrawRound(Canvas: TCanvas; Cl: TColor; vX, vY: integer);
procedure circle(Canvas: TCanvas;Cl: TColor; x0,y0,x,y:integer);
begin
with Canvas do
begin
pen.Color:=Cl;
brush.Color:=Cl;
brush.color:=Cl;
pixels[x0+x,y0+y]:=Cl;
pixels[x0+x,y0-y]:=Cl;
pixels[x0-x,y0-y]:=Cl;
pixels[x0-x,y0+y]:=Cl;
end;
end;
var
x0,y0,x,y,a,b:integer;
d1,d2:real;
begin
x0:=vX;
y0:=vY;
a:=10; b:=10; x:=0; y:=b;//a,b是宽高,自己调整
d1:=b*b+a*a*(-b+0.25);
circle(Canvas,CL,x0,y0,x,y);
while(b*b*(x+1)<a*a*(y-0.5))do
if(d1<0) then
begin
d1:=d1+b*b*(2*x+3);
x:=x+1;
circle(Canvas,CL,x0,y0,x,y);
end
else
begin
d1:=d1+b*b*(2*x+3)+a*a*(-2*y+2);
x:=x+1;
y:=y-1;
circle(Canvas,CL,x0,y0,x,y);
end;
circle(Canvas,CL,x0,y0,x,y);
d2:=sqr(b*(x+0.5))+sqr(a*(y-1))-sqr(a*b);
circle(Canvas,CL,x0,y0,x,y);
while (y>0)do
if(d2<0)then
begin
d2:=d2+b*b*(2*x+2)+a*a*(-2*y+3);
x:=x+1;
y:=y-1;
circle(Canvas,CL,x0,y0,x,y);
end
else
begin
d2:=d2+a*a*(-2*y+3);
y:=y-1;
circle(Canvas,CL,x0,y0,x,y);
end;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//DrawRound(Image1.Canvas,ClRed,X,Y);//这里有红色和黄色,自己调整
DrawRound(Image1.Canvas,ClYellow,X,Y);
end;
end.
展开全部
这个问题太简单了,首先你必须捕捉image控件的OnMouseClick事件,在这个事件里直接画图即可.比如:circle(x,y),也可调用画布的相关绘图功能.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不明白如此复杂的代码,为什么还说简单。搂住再追加300分,让大师给咱加注!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
控制面板里可以设置的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询