运行时,关于控件的拖放、选择、拉伸? 在运行的时候,怎样才能做到像在设计时操作控件?能够拖放、选中、拉伸和缩小?奉上100分,请高人指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.先确定哪个控件被选中 所有控件共用一个onclick sender即为选中控件 如果类不同用classtype 判断2.对作选中控件作标志,再设计你需要的操作,当然这又会用到 onmousedown,onmousemove,onmouseup等过程,总之一定能做出你想要的效果! 在Game,图形那个区里有,你去那找吧。 http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=30743 试试,不知道可不可以:在控件的OnMouseDown事件中:拖放:const sc_DragMove = $f012;begin ReleaseCapture; 控件.Perform(WM_SysCommand, sc_DragMove, 0);end;拉伸:const sc_DragSize = $61448;begin ReleaseCapture; 控件.Perform(WM_SysCommand, sc_DragSize, 0);end;选择应该就是:控件.SetCapture; 在控件的OnMouseDown事件中:拖放:const sc_DragMove = $f012;begin ReleaseCapture; 控件.Perform(WM_SysCommand, sc_DragMove, 0);end;拉伸:const sc_DragSize = $61448;begin ReleaseCapture; 控件.Perform(WM_SysCommand, sc_DragSize, 0);end;选择应该就是:控件.SetCapture; //改变控件位置及大小unit SizerControl;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TSizerControl = class(TCustomControl) private FControl: TControl; FRectList: Array [1..8] of TRect; FPosList: Array [1..8] of Integer; { Private declarations } protected { Protected declarations } public constructor Create(AOwner: TComponent; AControl: TControl); procedure CreateParams(var Params: TCreateParams); override; procedure Createhandle;override; procedure WmNcHitTest(var Msg: TWmNcHitTest); message wm_NcHitTest; procedure WmSize(var Msg:TWmSize); message wm_Size; procedure WmLButtonDown(var Msg: TWmLButtonDown); message wm_LButtonDown; procedure WmMove(var Msg: TWmMove); message Wm_Move; procedure Paint; override; procedure SizeControlExit(Sender: TObject); { Public declarations } published { Published declarations } end;const sc_DragMove: Longint = $F012;procedure Register;implementationuses djtool;constructor TSizerControl.Create(AOwner: TComponent; AControl: TControl);var R: TRect;begin inherited Create(AOwner); FControl := AControl; OnExit := SizeControlExit; R := FControl.BoundsRect; InflateRect(R, 2, 2); BoundsRect := R; Parent := FControl.Parent; FPosList[1] := htTopLeft; FPosList[2] := htTop; FPosList[3] := htTopRight; FPosList[4] := htRight; FPosList[5] := htBottomRight; FPosList[6] := htBottom; FPosList[7] := htBottomLeft; FPosList[8] := htLeft;end;procedure TSizerControl.CreateParams(var Params: TCreateParams);begin inherited CreateParams(Params); //增加透明特性 Params.ExStyle := Params.ExStyle + WS_EX_TRANSPARENT;end;procedure TSizerControl.Createhandle;begin inherited Createhandle; SetFocus;end;procedure TSizerControl.WmNcHitTest(var Msg: TWmNcHitTest);var Pt: TPoint; I: Integer;begin Pt := Point(Msg.XPos, Msg.YPos); Pt := ScreenToClient(Pt); Msg.Result := 0; //检测鼠标位置并改变状态 for I := 1 to 8 do if PtInRect(FRectList[I], Pt) then Msg.Result := FPosList[I]; if Msg.Result = 0 then inherited;end;procedure TSizerControl.WmSize(var Msg:TWmSize);var R: TRect;begin R := BoundsRect; InflateRect( R, -2, -2); FControl.BoundsRect := R; //计算8个黑方框 FRectList[1] := Rect(0 ,0, 5, 5); FRectList[2] := Rect(Width div 2 - 3, 0, Width div 2 + 2, 5); FRectList[3] := Rect(Width - 5, 0, Width, 5); FRectList[4] := Rect(Width - 5, height div 2 - 3, Width, Height div 2 + 2); FRectList[5] := Rect(Width - 5, Height - 5, Width, Height); FRectList[6] := Rect(Width div 2 - 3, Height - 5, Width div 2 + 2, Height); FRectList[7] := Rect(0, Height -5, 5, Height); FRectList[8] := Rect(0, Height div 2 - 3, 5, Height div 2 + 2);//-------------------------added by guozhaofeng 以下部分用于变动时实时显示高度和宽度// djtool.EdtWit.Text:=templen;// Edtlen.Text:=inttostr(Width);end;procedure TSizerControl.WmLButtonDown(var Msg: TWmLButtonDown);begin //执行拖动命令 Perform(Wm_SysCommand, sc_DragMove, 0);end;procedure TSizerControl.WmMove(var Msg: TWmMove);var R: TRect;begin R := BoundsRect; InflateRect( R, -2, -2); FControl.Invalidate; FControl.BoundsRect := R;end;procedure TSizerControl.Paint;var I: Integer;begin Canvas.Brush.Color := clBlack; for I := 1 to 8 do with FRectList[I] do Canvas.Rectangle (Left, Top, Right, Bottom);end;procedure TSizerControl.SizeControlExit(Sender: TObject);begin Free;end;procedure Register;begin RegisterNoicon([TSizerControl]);end;end. Corn1(玉米):你现在不知道有很多象这样混饭吃的人吗?无耻 其实多放几个plane也可以很好的控制! 请问如何把 SmallInt 转为 integer类型 恢复控件!!! 今天倒霉了散分下班前结!100分 如何使我的DELPHI程序节省内存开销? 如果不将图片存入数据库,还有其它方法进行存取操作吗?有的话怎么实现呢? 开一个线程就showmessage('Hello'),然后每秒在开一个这样的线程! 介绍几本初学者用的好书,谢谢了 请教实现大小写转换的函数? 关于多线程的一个具体问题的求教 FireMonkey 标题栏的图标如何更换? 请问如何知道今天的日期是星期几? 用FastReport做报表时,怎麽可以让每页都打印数据的合计?
2.对作选中控件作标志,再设计你需要的操作,当然这又会用到 onmousedown,onmousemove,onmouseup等过程,总之一定能做出你想要的效果!
在控件的OnMouseDown事件中:
拖放:
const
sc_DragMove = $f012;
begin
ReleaseCapture;
控件.Perform(WM_SysCommand, sc_DragMove, 0);
end;拉伸:
const
sc_DragSize = $61448;
begin
ReleaseCapture;
控件.Perform(WM_SysCommand, sc_DragSize, 0);
end;选择应该就是:
控件.SetCapture;
拖放:
const
sc_DragMove = $f012;
begin
ReleaseCapture;
控件.Perform(WM_SysCommand, sc_DragMove, 0);
end;拉伸:
const
sc_DragSize = $61448;
begin
ReleaseCapture;
控件.Perform(WM_SysCommand, sc_DragSize, 0);
end;选择应该就是:
控件.SetCapture;
unit SizerControl;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TSizerControl = class(TCustomControl)
private
FControl: TControl;
FRectList: Array [1..8] of TRect;
FPosList: Array [1..8] of Integer; { Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent; AControl: TControl);
procedure CreateParams(var Params: TCreateParams); override;
procedure Createhandle;override;
procedure WmNcHitTest(var Msg: TWmNcHitTest); message wm_NcHitTest;
procedure WmSize(var Msg:TWmSize); message wm_Size;
procedure WmLButtonDown(var Msg: TWmLButtonDown); message wm_LButtonDown;
procedure WmMove(var Msg: TWmMove); message Wm_Move;
procedure Paint; override;
procedure SizeControlExit(Sender: TObject); { Public declarations }
published
{ Published declarations }
end;
const
sc_DragMove: Longint = $F012;
procedure Register;implementation
uses djtool;constructor TSizerControl.Create(AOwner: TComponent; AControl: TControl);
var
R: TRect;
begin
inherited Create(AOwner);
FControl := AControl;
OnExit := SizeControlExit; R := FControl.BoundsRect;
InflateRect(R, 2, 2);
BoundsRect := R;
Parent := FControl.Parent;
FPosList[1] := htTopLeft;
FPosList[2] := htTop;
FPosList[3] := htTopRight;
FPosList[4] := htRight;
FPosList[5] := htBottomRight;
FPosList[6] := htBottom;
FPosList[7] := htBottomLeft;
FPosList[8] := htLeft;end;
procedure TSizerControl.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
//增加透明特性
Params.ExStyle := Params.ExStyle
+ WS_EX_TRANSPARENT;
end;procedure TSizerControl.Createhandle;
begin
inherited Createhandle;
SetFocus;
end;procedure TSizerControl.WmNcHitTest(var Msg: TWmNcHitTest);
var
Pt: TPoint;
I: Integer;
begin
Pt := Point(Msg.XPos, Msg.YPos);
Pt := ScreenToClient(Pt);
Msg.Result := 0;
//检测鼠标位置并改变状态
for I := 1 to 8 do
if PtInRect(FRectList[I], Pt) then
Msg.Result := FPosList[I];
if Msg.Result = 0 then
inherited;
end;
procedure TSizerControl.WmSize(var Msg:TWmSize);
var
R: TRect;
begin
R := BoundsRect;
InflateRect( R, -2, -2);
FControl.BoundsRect := R;
//计算8个黑方框
FRectList[1] := Rect(0 ,0, 5, 5);
FRectList[2] := Rect(Width div 2 - 3, 0, Width div 2 + 2, 5);
FRectList[3] := Rect(Width - 5, 0, Width, 5);
FRectList[4] := Rect(Width - 5, height div 2 - 3, Width, Height div 2 + 2);
FRectList[5] := Rect(Width - 5, Height - 5, Width, Height);
FRectList[6] := Rect(Width div 2 - 3, Height - 5, Width div 2 + 2, Height);
FRectList[7] := Rect(0, Height -5, 5, Height);
FRectList[8] := Rect(0, Height div 2 - 3, 5, Height div 2 + 2);
//-------------------------added by guozhaofeng 以下部分用于变动时实时显示高度和宽度
// djtool.EdtWit.Text:=templen;
// Edtlen.Text:=inttostr(Width);
end;
procedure TSizerControl.WmLButtonDown(var Msg: TWmLButtonDown);
begin
//执行拖动命令
Perform(Wm_SysCommand, sc_DragMove, 0);
end;procedure TSizerControl.WmMove(var Msg: TWmMove);
var
R: TRect;
begin
R := BoundsRect;
InflateRect( R, -2, -2);
FControl.Invalidate;
FControl.BoundsRect := R;
end;procedure TSizerControl.Paint;
var
I: Integer;
begin
Canvas.Brush.Color := clBlack;
for I := 1 to 8 do
with FRectList[I] do
Canvas.Rectangle (Left, Top, Right, Bottom);
end;procedure TSizerControl.SizeControlExit(Sender: TObject);
begin
Free;
end;procedure Register;
begin
RegisterNoicon([TSizerControl]);
end;end.