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

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

    保存会话数据的两种技术 Cookie Cookie 是客户端技术,程序把每个用户的数据以cookie的形式写给用户的浏览器.当用户使用浏览器再去访问服务器中的web资源时,就会带着各自的数据去.web ...

  2. j2ee学习笔记 Filter过滤器

    作用:过滤response和request对象的内容 使用: Filter是J2EE的一个接口,自定义Filter需要实现该接口,并重写所有的方法. Filter提供的方法: init() doFil ...

  3. iOS中保证线程安全的几种方式与性能对比

    来源:景铭巴巴 链接:http://www.jianshu.com/p/938d68ed832c 一.前言 前段时间看了几个开源项目,发现他们保持线程同步的方式各不相同,有@synchronized. ...

  4. IT行业智力测试

    1.有10筐苹果,其中有1筐是次品,正品苹果每个10两,次品苹果每个9两,现有一称,问怎么一次称出次品是哪筐? 2.有甲.乙.丙.丁四个人,要在夜里过一座桥.他们通过这座桥分别需要耗时1.2.5.10 ...

  5. Python开发实战教程(8)-向网页提交获取数据

    来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...

  6. PS之放射背景

    效果图 素材 新建图层,填充颜色 新建图层,矩形工具画条形 滤镜-扭曲-极坐标 合并图层,效果如下 新建图层,画一个适当的圆 滤镜-模糊-高斯模糊 将素材人物抠出来放在中间

  7. CentOS&nbsp;6.4&nbsp;图文安装教…

    点评:CentOS 6.4是最新的出的系统,这里分享下安装教程,有些设置大部分教程没出现过,特分享下,方便需要的朋友 CentOS 6.4 下载地址: http://www.jb51.net/soft ...

  8. Navicat 看历史执行SQL

    Navicat可以通过这个框口看手动操作所执行的代码操作

  9. Java设计模式--单列设计模式

    设计模式:解决某一类问题行知最有效的方法.java有23种设计模式 单列设计模式: 解决一个类在内存中只存在一个对象 思路:(要保证对象的唯一性) 1.为了避免其它程序建立该对象,先禁止替他类创建改对 ...

  10. Python编写相关注意事项

    1.# -*- coding: utf-8 -*-代码首部添加这个,不然会报Non_ASCII charater错误 python闭包:实际应用场景1.保持闭包运行完后的环境: 2.根据外部作用域的局 ...