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

// 由于拐角这点手动精确实在困难 所以用范围 范围+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. telnet的使用

    1.要打开 telnet 不是内部或外部 命令 解决方案: 程序添加删除功能,添加即可 或法二 C:\WINDOWS\system32\telnet.exe (或用C:\WINDOWS\system3 ...

  2. Visual Studio 调试技巧 (三) -- 调试第三方组件代码

    上次我们提到,没有源代码而且没有调试符号,我们也可以 Debug.有人可能会问,我什么时候需要在这种情况下调试吗?! 是的.比方说,我们用了某些第三方的组件,这些组件里面难免也会有 Bug.就算是微软 ...

  3. VC++ 响应回车键的2种方法

    众所周知,VC++响应回车键经常用的方法是利用 BOOL PreTranslateMessage(MSG* pMsg) 截取回车键消息,如: if (pMsg->message == WM_KE ...

  4. CentOS7上Nginx的使用

    Nginx 的启动 指定配置文件的方式启动nginx # nginx -c /etc/nginx/nginx.conf 对于yum安装的nginx,使用systemctl命令启动 # systemct ...

  5. 第六篇:web之python框架之django

    python框架之django   python框架之django 本节内容 web框架 mvc和mtv模式 django流程和命令 django URL django views django te ...

  6. 3G/4G网卡使用

    整体架构: pppd call option & ----------↓---------- option脚本(设置PPP连接) ----------↓---------- chat脚本(进行 ...

  7. Android源码编译过程之九鼎开发板

    build_kernel() { # 进入源码顶层目录 cd ${BS_DIR_KERNEL} || # 编译配置文件 make ${BS_CONFIG_KERNEL} ARCH=arm CROSS_ ...

  8. Bootstrap--全局CSS样式之排版

    Bootstrap的排版样式大致和html基本元素一样,没什么大的区别,就是对元素加了样式. (1)标题 HTML 中的所有标题标签,<h1> 到 <h6> 均可使用.另外,还 ...

  9. /etc目录深入理解

    /etc This is the nerve center of your system, it contains all system related configuration files in ...

  10. C++ 类访问控制(public/protected/private)

    第一:private, public, protected 访问标号的访问范围. private:只能由1.该类中的函数.2.其友元函数访问. 不能被任何其他访问,该类的对象也不能访问. protec ...