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

// 由于拐角这点手动精确实在困难 所以用范围 范围+3 这样很容易就找到这一点了
procedure CtrlMouseMove(Ctrl: TWinControl; Shift: TShiftState;X, Y: Integer);
begin
with Ctrl do
begin
if (X >= ) and (X <= ) then
begin
if (Y >= ) and (Y <= ) then Cursor := crSizeNWSE;
if (Y > ) and (Y < Height - ) then Cursor := cRsizewe;
if (Y >= Height - ) and (Y <= Height) then Cursor := crSizeNESW;
end
else if (X > ) and (X < Width - ) then
begin
if (Y >= ) and (Y <= ) then Cursor := crSizeNS;
if (Y > ) and (Y < Height - ) then Cursor := cRarrow;
if (Y >= Height - ) and (Y <= Width) then Cursor := crSizeNS;
end
else if (X >= Width - ) and (X <= Width) then
begin
if (Y >= ) and (Y <= ) then Cursor := crSizeNESW;
if (Y > ) and (Y < Height - ) then Cursor := cRsizewe;
if (Y >= Height - ) 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 >= ) and (X <= ) then
begin
if (Y >= ) and (Y <= ) then WParam:=$F004;
if (Y > ) and (Y < Height - ) then WParam:=$F001;
if (Y >= Height - ) and (Y <= Height) then WParam:=$F007;
end
else if (X > ) and (X < Width - ) then
begin
if (Y >= ) and (Y <= ) then WParam:=$F003;
if (Y > ) and (Y < Height - ) then WParam:=$F012;
if (Y >= Height - ) and (Y <= Width) then WParam:=$F006;
end
else if (X >= Width - ) and (X <= Width) then
begin
if (Y >= ) and (Y <= ) then WParam:=$F005;
if (Y > ) and (Y < Height - ) then WParam:=$F002;
if (Y >= Height - ) and (Y <= Width) then WParam:=$F008;
end;
ReleaseCapture; // 不断调用API,冒充鼠标释放
SendMessage(Handle,WM_SYSCOMMAND,WParam,); // 发消息改变ctrl的位置,受启发,也可改成SendMessage(Handle,WM_NCLBUTTONDOWN,HTCAPTION,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;

参考: http://www.cnblogs.com/xe2011/p/3426494.html

------------------------------------------------------------------------------------------

这些 WParam:=$F004; 是什么意思呢?MSDN说明:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

还是不懂.

另外,这个例子为啥右键不能拖动?不也是MouseDown吗?

------------------------------------------------------------------------------------------

运行时改变控件的大小(点击后立刻ReleaseCapture,然后计算位移,最后发消息改变位置)——最有趣的是TPanel其实也有窗口标题,因此可发HTCAPTION消息的更多相关文章

  1. MFC中改变控件的大小和位置

    用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...

  2. MFC中改变控件的大小和位置(zz)

    用CWnd类的函数MoveWindow()或SetWindowPos()能够改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...

  3. Android中动态改变控件的大小的一种方法

    在Android中有时候我们需要动态改变控件的大小.有几种办法可以实现  一是在onMeasure中修改尺寸,二是在onLayout中修改位置和尺寸.这个是可以进行位置修改的,onMeasure不行. ...

  4. C# 窗体缩放的时候同步改变控件的大小和字体

    最新在写个小程序,需要窗体填满各种尺寸的显示器,同时需要同步缩放控件的大小.于是就写了个类,简单的调用一下即可解决问题. 这个类可以同步缩放控件的位置,宽度高度,字体大小. 使用的时候在FormLoa ...

  5. MFC 改变控件的大小和位置

    mfc 改变控件大小和位置用到的函数: ) void MoveWindow(int x, int y, int nWidth, int nHeight); ) void MoveWindow(LPCR ...

  6. ios 运行时特征,动态改变控件字体大小

    需求:ex: 在不同尺寸的iPhone上面显示的字体大小不一样 https://github.com/rentzsch/jrswizzle #import <UIKit/UIKit.h> ...

  7. C# 运行时通过鼠标拖动改变控件的大小

    来源:http://blog.csdn.net/yanleigis/article/details/1819447 using System; using System.Collections.Gen ...

  8. C++ MFC 改变控件大小和位置

    用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...

  9. Winform窗体控件自适应大小

    自己写的winform窗体自适应大小代码,代码比较独立,很适合贴来贴去不会对原有程序造成影响,可以直接继承此类或者把代码复制到自己的代码里面直接使用 借鉴了网上的一些资料,最后采用重写WndProc方 ...

随机推荐

  1. linux下配置php Apache mysql

    一 Apache部分 http://www.cnblogs.com/bluewelkin/p/3805107.html里面是纠正了原文的一些小错误,即可正常安装 1.su 命令2.安装apr-1.3. ...

  2. Android Studio使用SVN,与eclipse共同开发。

    Android Studio(下称AS)开发工具目前已经迅速在世界普遍使用起来,而在很多一部分公司内部,仍然有部分老员工坚持使用eclipse + SVN,而不改用AS,这使得想使用AS的小伙伴们都深 ...

  3. CSS hack常用方案(摘选)

    邮箱因为默认了line-height?:170%,导致采用table元素时继承问题,可以采用line-height:50% 很好解决. 常 在使用float时,后面的显示不正常,因为继承了float了 ...

  4. Nginx Resource

    Nginx中URL转换成小写首先编译安装nginx_lua_module模块server节: location / { if($uri ~ [A-Z]){ rewrite_by_lua 'return ...

  5. Linux安装QQ 2017

    网上有很多wineQQ,是基于2012或者2013做的,然而当安装好后登录他会提示版本过来,我在优麒麟的应用商店里找到了一个基于国际版QQ的Wine版本,这里说下安装过程. 先上两张成果图: 下载地址 ...

  6. JS实现图片宽高的等比缩放

    关于图片宽高的等比缩放,其实需求就是让图片自适应父容器的宽高,并且是等比缩放图片,使图片不变形. 例如,需要实现如下的效果: 要实现上面的效果,需要知道图片的宽高,父容器的宽高,然后计算缩放后的宽高. ...

  7. HTML+CSS基础学习笔记(5)

    一.文字排版--字体 Eg: body{font-family:"宋体";} body{font-family:"Microsoft Yahei";}//微软雅 ...

  8. asp.net中WebForm.aspx与类文件分离使用

    第一步:新建一个web项目和类库,新建一个页面和映射类文件: 第二步:在页面中,删除默认映射类,添加服务器控件. 1.更改映射类命名空间: 原: <%@ Page Language=" ...

  9. 正则表达式-delphi

    一.工具选择 在 Delphi 中使用正则表达式, 目前 PerlRegEx 应该是首选, 准备彻底而细致地研究它. 官方网站: http://www.regular-e­xpressions.inf ...

  10. list集合中指定字段去重

    在开发中,有时会需要指定字段去重,以下为实现方法: 假设有个房地产权的类,其中宗地代码ZDDM值重复,而我们在前端页面显示时,只需要一条数据,因为公共字段都一样: IEqualityComparer需 ...