用鼠标点击来画这个多边形,就是通过在imagemousedown、imagemousemove、imagemouseup中输入代码的方式。
解决方案 »
- 麻烦管理删 个帖
- 二叉树的数据库存储
- 我把ADODataSET 的MaxRecord=100,那如何取得下一100条记录呢。。。。。
- 關於Tcomboboxex控件
- 关于数据字典的问题?
- 请问要在自己的程序里调用像TADOConnection的数据连接属性向导对话框要怎么做呢?
- 什么控件可以画流程图?(Tchart可以吗?怎么用?)
- 100分求助!!!工作真难找,天天到处跑,如何获得第一份工作,有同情心者请回答
- Delphi可以开发操作系统吗?
- 在word97中如何输入数学公式,如(西格码)?
- 还是有关于delphi 6.0+ado+odbc后插入,删除,异常的问题
- 今天太郁闷了,在线散分!!!!
//技术,但是那也是很好做的,你自己试试吧!!不会的话,你再问我!
//还有就是,解决了,可要给我加分啊!!!哈哈哈
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
headPoint:Array of Tpoint;//声明一个保存多边形顶点的动态数组
pointcount:integer=1;//顶点的个数
_end:boolean=false; //是否停止绘制多边形
implementation{$R *.DFM}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if _end=false then
begin
if button=mbleft then//是否是鼠标左键按下
begin
SetLength(headpoint,pointcount);//动态分配数组的大小
headpoint[pointcount-1]:=point(x,y);
if pointcount=1 then //移动画笔的初始点
canvas.MoveTo(headpoint[0].x,headpoint[0].y)
else
canvas.MoveTo(headpoint[pointcount-2].x,headpoint[pointcount-2].y);
canvas.Pen.Color:=clred;//画笔颜色
canvas.LineTo(x,y); //绘制直线
inc(pointcount); //增加顶点个数
end
else begin //右键按下
headpoint[pointcount]:=headpoint[0];//形成封闭的多边形
canvas.Polyline(headpoint);//绘制边线
canvas.Polygon(headpoint); //填充多边形
_end:=true;//停止绘制
end;
end;
end;end.
中有TPolyline!
谢谢你的范例,分没问题,我待会给你。
但我不大知道橡皮筋”技术的原理,能否告诉我?
[email protected]
//情况,以便让用户决定下一步的操作。是不是很人性化??
//这只是个范例,你可以自己扩展……
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
headPoint:Array of Tpoint;//声明一个保存多边形顶点的动态数组
pointcount:integer=1;//顶点的个数
_end:boolean=false; //是否停止绘制多边形
implementation{$R *.DFM}
var
head_pos,tail_pos:Tpoint;
drawing:Boolean;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if _end=false then
begin
SetLength(headpoint,pointcount);//动态分配数组的大小
headpoint[pointcount-1]:=point(x,y);
head_pos:=point(x,y); //初始化时,将直线的起点终点赋为同一点
tail_pos:=head_pos;
inc(pointcount);//增加顶点个数
if button=mbleft then//是否是鼠标左键按下
drawing:=true
else begin //右键按下
headpoint[pointcount]:=headpoint[0];//形成封闭的多边形
canvas.Polyline(headpoint);//绘制边线
canvas.Polygon(headpoint); //填充多边形
_end:=true;//停止绘制
drawing:=false;
end;
end;
end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Drawing=true then//还在进行绘制吗
begin
with self.canvas do
begin
pen.Mode:=pmNot;//设定画笔的模式为反转模式;这样做的目的就是
//可以简单快速的擦除前一次画的线
//画前一次的直线
MoveTo(head_pos.x,head_pos.y);
lineto(tail_pos.x,tail_pos.y);
//画本次的直线
MoveTo(head_pos.x,head_pos.y);
lineto(x,y);
//修正直线终点位置
tail_pos:=point(x,y);
end;
end;
end;end.