在运行时改变控件的大小

 

 

//光标在控件不同位置时的样式

// 由于拐角这点手动精确实在困难 所以用范围 范围+3 这样很容易就找到这一点了

procedure CtrlMouseMove(Ctrl: TWinControl; Shift: TShiftState;X, Y: Integer);
begin
   with Ctrl do
   begin
      if (X >= 0) and (X <= 3) then
      begin
        if (Y >= 0) and (Y <= 3)                then  Cursor := crSizeNWSE;
        if (Y > 3) and (Y < Height - 3)         then  Cursor := cRsizewe;
        if (Y >= Height - 3) and (Y <= Height)  then  Cursor := crSizeNESW;
      end
      else if (X > 3) and (X < Width - 3) then
      begin
        if (Y >= 0) and (Y <= 3)                then  Cursor := crSizeNS;
        if (Y > 3) and (Y < Height - 3)         then  Cursor := cRarrow;
        if (Y >= Height - 3) and (Y <= Width)   then  Cursor := crSizeNS;
      end
      else if (X >= Width - 3) and (X <= Width) then
      begin
        if (Y >= 0) and (Y <= 3)                then  Cursor := crSizeNESW;
        if (Y > 3) and (Y < Height - 3)         then  Cursor := cRsizewe;
        if (Y >= Height - 3) and (Y <= Width)   then  Cursor := crSizeNWSE;
      end;
   end;
end;

 

//改变控件的大小

procedure CtrlMouseDown(Ctrl: TWinControl; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);
var
  WParam: Integer;
begin
  with Ctrl do
  begin
    if (X >= 0) and (X <= 3) then
    begin
      if (Y >= 0) and (Y <= 3)                 then  WParam:=$F004;
      if (Y > 3)  and (Y < Height - 3)         then  WParam:=$F001;
      if (Y >= Height - 3) and (Y <= Height)   then  WParam:=$F007;
    end
    else if (X > 3) and (X < Width - 3) then
    begin
      if (Y >= 0) and (Y <= 3)                 then  WParam:=$F003;
      if (Y > 3) and (Y < Height - 3)          then  WParam:=$F012;
      if (Y >= Height - 3) and (Y <= Width)    then  WParam:=$F006;
    end
    else if (X >= Width - 3) and (X <= Width)  then
    begin
      if (Y >= 0) and (Y <= 3)                 then  WParam:=$F005;
      if (Y > 3) and (Y < Height - 3)          then  WParam:=$F002;
      if (Y >= Height - 3) and (Y <= Width)    then  WParam:=$F008;
    end;
    ReleaseCapture;
    SendMessage(Handle,WM_SYSCOMMAND,WParam,0);
  end;
end;

 

使用

procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  CtrlMouseDown(Panel1, Button, Shift, X, Y);
end;

procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  CtrlMouseMove(Panel1, Shift, X, Y);
end;

 

转载于:https://www.cnblogs.com/xe2011/p/3426494.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作用是在运行时刻自动对其它可视控件进行动态的位置/大小调整.这个控件实现的功能和VB.Net的窗体布局功能类似.比如你的窗体中有一个DBGrid控件,占了很大一部分,下边有几个按钮 现在需要窗体的大小可调,以使DBGrid可以看到更多的数据,这样的话,窗体上的控件就都需要调整,不然只有窗体变化,而控件不动的话就达不到预期效果,而且很难看.原来的方式是在窗口的Resize事件中添加调整控件大小/位置的代码,这样做的话比较麻烦,要自己手动去计算宽度/偏移,然后将这些代码写死在程序中,以后增加控件或者调整布局都需要重新计算/修改代码,不利于维护. 有了这个控件就方便多了,Resize事件中一行代码不用写,只需将这个控件拖动到窗体上,然后设置被调整控件的Tag属性,在运行时刻就可以进行调整了.VB6ResizerLib 2.0 版本新增分隔条控件,运行时可动态调整.同时修改了1.x版本中控件在退出程序前不会被释放及其导致的一系列问题.VB6ResizerLib 2.2 修正了2.0版本中使用DesignTimeInit模式的时候可能会导致VB崩溃的问题.使用说明:启动VB程序,打开一个工程.按Ctrl+T打开部件对话框.找到并选中VB6ResizerLib后点击确定.将工具箱中新出现的VB6Resizer控件拖动到窗体上即可.被调整控件需要使用Tag属性定义调整规则,方式如下:H-调整控件自身高度.W-调整空间自身宽度.T-调整控件与容器顶部距离.L-调整控件与容器左侧距离.例如―HW‖表示自动调整高度和宽度.TL的优先级高于HW,如果Tag同时包含T和H,则仅T有效.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值