程序运行如何拖动控件改变大小

Zoogreen 2004-07-28 03:54:05
比如 image 控件, 程序运行时,可随意拖动image大小。
...全文
165 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zoogreen 2004-08-05
  • 打赏
  • 举报
回复
好方法,TGraphicControl没有的,放到 Twincontrol里就可以了,3q
stubborndonkey 2004-07-28
  • 打赏
  • 举报
回复
他那段代码是往窗口发消息改变大小的,而TGRAPHICCONTROL是没有WINDOW的,所以无法处理这类消息.
你把IMAGE扔到一个PANEL里不就完了.设置IMAGE为CLIENTALIGN,这样IMAGE就自动随PANEL改变大小.
Zoogreen 2004-07-28
  • 打赏
  • 举报
回复
image 是 TGraphicControl 继承下来的,所以类型转化出错了。不过用了,
TGraphicControl,或者 Tcontrol 也不能托动我的image图象改变大小嘛。不知道怎么回事
wizardqi 2004-07-28
  • 打赏
  • 举报
回复
可以将TWinControl 变为TControl;
Zoogreen 2004-07-28
  • 打赏
  • 举报
回复
image难道不是TwonControl继承下来的,还是少了属性,其它的好象可以的
yinzhiw 2004-07-28
  • 打赏
  • 举报
回复
我用上面那程序
没有问题的
Zoogreen 2004-07-28
  • 打赏
  • 举报
回复
提示出错啊,invalid class typecast 在mousemove事件里
juliens 2004-07-28
  • 打赏
  • 举报
回复
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
procedure ManipulateControl(WinControl: TWinControl; Shift: TShiftState; X, Y, Precision: integer);
//Precision:精度,该方法可以在onmousemove中调用
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.ManipulateControl(WinControl: TWinControl;
Shift: TShiftState; X, Y, Precision: integer);
var SC_MANIPULATE: Word;
begin
//光标在控件的最左侧
if (X <= Precision) and (Y > Precision) and (Y < WinControl.Height - Precision)then
begin
SC_MANIPULATE := $F001;
WinControl.Cursor := crSizeWE;
end
//光标在控件的最右侧
else if (X >= WinControl.Width - Precision) and (Y > Precision) and (Y < WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F002;
WinControl.Cursor := crSizeWE;
end
//光标在控件的最上侧
else if (X > Precision) and (X < WinControl.Width - Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F003;
WinControl.Cursor := crSizeNS;
end
//光标在控件的左上角
else if (X <= Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F004;
WinControl.Cursor := crSizeNWSE;
end
//光标在控件的右上角
else if (X >= WinControl.Width-Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F005;
WinControl.Cursor := crSizeNESW ;
end
//光标在控件的最下侧
else if (X > Precision) and (X < WinControl.Width - Precision) and (Y >= WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F006;
WinControl.Cursor := crSizeNS;
end
//光标在控件的左下角
else if (X <= Precision) and (Y >= WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F007;
WinControl.Cursor := crSizeNESW;
end
//光标在控件的右下角
else if (X >= WinControl.Width - Precision) and (Y >= WinControl.Height - Precision) then
begin
SC_MANIPULATE := $F008;
WinControl.Cursor := crSizeNWSE;
end
//光标在控件的客户区(移动整个控件)
else if (X > 5) and (Y > 5) and (X < WinControl.Width - 5) and (Y < WinControl.Height - 5)then
begin
SC_MANIPULATE := $F009;
WinControl.Cursor := crSizeAll;
end
else
begin
SC_MANIPULATE := $F000;
WinControl.Cursor := crDefault;
end;

if Shift = [ssLeft] then
begin
ReleaseCapture;
WinControl.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
end;

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

end.

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧