运行时改变控件的大小(点击后立刻ReleaseCapture,然后计算位移,最后发消息改变位置)——最有趣的是TPanel其实也有窗口标题,因此可发HTCAPTION消息
//光标在控件不同位置时的样式
// 由于拐角这点手动精确实在困难 所以用范围 范围+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消息的更多相关文章
- MFC中改变控件的大小和位置
用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...
- MFC中改变控件的大小和位置(zz)
用CWnd类的函数MoveWindow()或SetWindowPos()能够改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...
- Android中动态改变控件的大小的一种方法
在Android中有时候我们需要动态改变控件的大小.有几种办法可以实现 一是在onMeasure中修改尺寸,二是在onLayout中修改位置和尺寸.这个是可以进行位置修改的,onMeasure不行. ...
- C# 窗体缩放的时候同步改变控件的大小和字体
最新在写个小程序,需要窗体填满各种尺寸的显示器,同时需要同步缩放控件的大小.于是就写了个类,简单的调用一下即可解决问题. 这个类可以同步缩放控件的位置,宽度高度,字体大小. 使用的时候在FormLoa ...
- MFC 改变控件的大小和位置
mfc 改变控件大小和位置用到的函数: ) void MoveWindow(int x, int y, int nWidth, int nHeight); ) void MoveWindow(LPCR ...
- ios 运行时特征,动态改变控件字体大小
需求:ex: 在不同尺寸的iPhone上面显示的字体大小不一样 https://github.com/rentzsch/jrswizzle #import <UIKit/UIKit.h> ...
- C# 运行时通过鼠标拖动改变控件的大小
来源:http://blog.csdn.net/yanleigis/article/details/1819447 using System; using System.Collections.Gen ...
- C++ MFC 改变控件大小和位置
用CWnd类的函数MoveWindow()或SetWindowPos()可以改变控件的大小和位置. void MoveWindow(int x,int y,int nWidth,int nHeight ...
- Winform窗体控件自适应大小
自己写的winform窗体自适应大小代码,代码比较独立,很适合贴来贴去不会对原有程序造成影响,可以直接继承此类或者把代码复制到自己的代码里面直接使用 借鉴了网上的一些资料,最后采用重写WndProc方 ...
随机推荐
- PureMVC(JS版)源码解析(二):Notification类
上篇博客,我们已经就PureMVC的设计模式进行的分析,这篇博文主要分析Notification(消息)类的实现. 通过Notification的构造函数可以看出,PureMVC中的Notificat ...
- 为什么java不支持多重继承?
什么是钻石问题?如下图所示,B和C继承于A,D继承B和C(多重继承),在D中调用A的方法时,无法判断是调用B中的实现还是C的实现,下图继承关系是个菱形,所以该问题又叫做菱形问题. 如果java要解决这 ...
- Java基础知识强化之集合框架笔记56:Map集合之HashMap集合(HashMap<String,Student>)的案例
1. HashMap集合(HashMap<String,Student>)的案例 HashMap是最常用的Map集合,它的键值对在存储时要根据键的哈希码来确定值放在哪里. HashMap的 ...
- Grant-Permission.ps1
Grant-Permission.ps1 Download the EXE version of SetACL 3.0.6 for 32-bit and 64-bit Windows. Put set ...
- Java线性表的排序
Java线性表的排序 ——@梁WP 前言:刚才在弄JDBC的时候,忽然觉得order-by用太多了没新鲜感,我的第六感告诉我java有对线性表排序的封装,然后在eclipse里随便按了一下“.” ,哈 ...
- codeforces 505C Mr. Kitayuta, the Treasure Hunter(dp)
题意:有30001个岛,在一条线上,从左到右编号一次为0到30000.某些岛屿上有些宝石.初始的时候有个人在岛屿0,他将跳到岛屿d,他跳跃的距离为d.如果当前他跳跃的距离为L,他下一次跳跃的距离只能为 ...
- android应用一(调用WebServices)
搞了一个月的android,现学现卖,终于还是搞完了,停下来,整理思路,写写记录吧. 我们知道android访问远程数据库主要有两种协议,一种是SOAP,另外一种就是HTTP.而我们再看看WebSer ...
- PHP能得到你是从什么页面过来的,r…
在开发web程序的时候,有时我们需要得到用户是从什么页面连过来的,这就用到了referer. 它是http协议,所以任何能开发web程序的语言都可以实现,比如jsp中是: request.getHea ...
- android Lib
Android 支持库软件包含可以添加至应用的多个库.每个库均支持特定范围的 Android 平台版本和功能. 本指南介绍了各支持库提供的重要功能和版本支持,从而帮助您决定在应用中添加哪些支持库.一般 ...
- <>跟!=
这两个是没有区别的,都是不等于