如何实现在窗体中画线和箭头,可以拖拉,可以缩放功能(200分)

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

yihang

Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现在窗体中画线和箭头,可以拖拉,可以缩放的功能。

例如窗体上有三个控件A、B、C,我要用鼠标实现从A画带箭头的线连到B或C,
或者从B画线到A和C,并能随意修改连线。还要读出窗体上A、B、C的所有连线的
情况。

请大家帮忙,先谢了!
 
写一个class
TTwoPoint=packed record //线的起始点和终结点,在终结点上画箭头
tpStart: Integer;
tpEnd: Integer;
end;
TMyArrow=class(TGraphiControl)
private
FmyArrow: TTwoPoint;
FLineWidth: Integer;
FLineColor: TColor;
procedure DrawArrow;
procedure DrawLine;
public
procedure DrawMyArrow; //箭头画法,只要一些简单的数学运算就可以算出箭头另外四个坐标
end;
 
可以拖拉,可以缩放的功能[?]
 
我以前曾经做过一个程序
主要是模拟autocad 的功能 例如 画矩形 ,直线等几何图形 ;
因时间长了找不到源程序了 只能提供给你一些思路
主要思路是:
定义一些对象 例如 tline trectangle 等

type
tarrow =class (tojbect)
top,left,bottom,right:integer ;//保存箭头的位置信息
.... //其它一些属性
draw(); //画箭头
zoom () ;//放大缩小 只要计算 箭头的位置就可以了
.......
end;
然后在程序中 画一个箭头只要他建一个实例就行了 在 paint 事件中只要执行 arrow1.draw



 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1049697
先声明了,对Image和Shape不管用,如果想用
就放到Panel上面,你可以自己写一个这样的组合控件嘛。
Image.stretch设置true就行了。
不过,一般情况下,你不要听我的,因为,
看着我的眼睛,明白了吧,
我是来混分的。[:D]
 
bubble:我不是要实现控件的拖拉和缩放,
而是要从一个button控件画带箭头的线连到另一个控件,并这线可缩放、可拖拉。
不过还是谢谢你!!!
 
我想实现在窗体中画线和箭头,可以拖拉,可以缩放的功能。

例如窗体上有三个控件A、B、C,我要用鼠标实现从A画带箭头的线连到B或C,
或者从B画线到A和C,并能随意修改连线。还要读出窗体上A、B、C的所有连线的
情况。

请大家帮忙,先谢了!
//==============================================================================
//任意摆布一个控件(拖动、放大、缩小)******************************************
//==============================================================================
procedure ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer);
var SC_MANIPULATE: Word;
begin
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最左侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (X<=Precision) and (Y>Precision) and (Y<Control.Height-Precision)
then begin
SC_MANIPULATE := $F001;
Control.Cursor := crSizeWE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最右侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X>=Control.Width-Precision) and (Y>Precision) and (Y<Control.Height-Precision)
then begin
SC_MANIPULATE := $F002;
Control.Cursor := crSizeWE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最上侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X>Precision) and (X<Control.Width-Precision) and (Y<=Precision)
then begin
SC_MANIPULATE := $F003;
Control.Cursor := crSizeNS;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的左上角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X<=Precision) and (Y<=Precision)
then begin
SC_MANIPULATE := $F004;
Control.Cursor := crSizeNWSE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的右上角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X>=Control.Width-Precision) and (Y<=Precision)
then begin
SC_MANIPULATE := $F005;
Control.Cursor := crSizeNESW ;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最下侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X>Precision) and (X<Control.Width-Precision) and (Y>=Control.Height-Precision)
then begin
SC_MANIPULATE := $F006;
Control.Cursor := crSizeNS;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的左下角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X<=Precision) and (Y>=Control.Height-Precision)
then begin
SC_MANIPULATE := $F007;
Control.Cursor := crSizeNESW;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的右下角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X>=Control.Width-Precision) and (Y>=Control.Height-Precision)
then begin
SC_MANIPULATE := $F008;
Control.Cursor := crSizeNWSE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的客户区(移动整个控件)******************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X>5) and (Y>5) and (X<Control.Width-5) and (Y<Control.Height-5)
then begin
SC_MANIPULATE := $F009;
Control.Cursor := crSizeAll;
end
else begin
SC_MANIPULATE := $F000;
Control.Cursor := crDefault;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if Shift=[ssLeft] then
begin
ReleaseCapture;
Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
end;



example:

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm_Main.Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
Caption := IntToStr(X) + '/' + IntToStr(Y);
ManipulateControl((Sender as TControl), Shift, X, Y, 10);
end;


10为精度
 
后退
顶部