首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么在程序运行期用鼠标拖动控件并能改变其大小

2012-02-11 
如何在程序运行期用鼠标拖动控件并能改变其大小在程序运行的时候,可以用鼠标把某控件拖到窗体内的任意地方

如何在程序运行期用鼠标拖动控件并能改变其大小
在程序运行的时候,可以用鼠标把某控件拖到窗体内的任意地方并能改变其大小,就像在设计阶段时的效果一样.请各位大虾们指教,谢谢!      
       


[解决办法]
转贴
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Menus, ExtCtrls;

type TMyControl = Class(TControl);

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
private
procedure MyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;


implementation

{$R *.DFM}

procedure TForm1.MyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
(Sender as TControl).Perform(WM_SYSCOMMAND,$F012,0);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
I:Integer;
begin
for I:=0 to Form1.ComponentCount-1 do
begin
if (Form1.Components[I] is TControl) then
begin
TMyControl(Form1.Components[I]).OnMouseDown:=MyMouseDown;
end;
end;
end;

end.

热点排行