C#实现拖拽控件边控,动态改变大小;

public partial class ResizableRichTextBox : RichTextBox

{

public ResizableRichTextBox()

{

InitializeComponent();

}

public ResizableRichTextBox(IContainer container)

{

container.Add(this);

InitializeComponent();

}

DllImport("user32.dll")

private static extern int GetSystemMetrics(int nIndex);

private const int WM_NCHITTEST = 0x84;

private const int HTBOTTOM = 15;

private const int HTBOTTOMLEFT = 16;

private const int HTBOTTOMRIGHT = 17;

private const int HTTOP = 12;

private const int HTTOPLEFT = 13;

private const int HTTOPRIGHT = 14;

private const int HTLEFT = 10;

private const int HTRIGHT = 11;

private const int WM_EXPAND = WM_USER + 67;

private const int WM_USER = 0x0400;

protected override void WndProc(ref Message m)

{

base.WndProc(ref m);

switch (m.Msg)

{

case WM_NCHITTEST:

base.WndProc(ref m);

Point vPoint = new Point((int)m.LParam & 0xFFFF,

(int)m.LParam >> 16 & 0xFFFF);

vPoint = this.PointToClient(vPoint);

if (vPoint.X <= 5)

{

if (vPoint.Y <= 5)

m.Result = (IntPtr)HTTOPLEFT;

else if (vPoint.Y >= this.Height - 5)

m.Result = (IntPtr)HTBOTTOMLEFT;

else

m.Result = (IntPtr)HTLEFT;

}

else if (vPoint.X >= this.Width - 5)

{

if (vPoint.Y <= 5)

m.Result = (IntPtr)HTTOPRIGHT;

else if (vPoint.Y >= this.Height - 5)

m.Result = (IntPtr)HTBOTTOMRIGHT;

else

m.Result = (IntPtr)HTRIGHT;

}

else if (vPoint.Y <= 5)

m.Result = (IntPtr)HTTOP;

else if (vPoint.Y >= this.Height - 5)

m.Result = (IntPtr)HTBOTTOM;

break;

}

}

}

相关推荐
不剪发的Tony老师5 分钟前
数据库行业竞争加剧,MySQL 9.3.0 企业版开始支持个人下载
数据库·mysql
weixin_434255618 分钟前
命令行快速上传文件到SFTP服务器(附参考示例)
linux·运维·服务器
掘金-我是哪吒25 分钟前
分布式微服务系统架构第133集:运维服务器6年经验,高并发,大数据量系统
运维·服务器·分布式·微服务·系统架构
Funny-Boy1 小时前
Reactor (epoll实现基础)
服务器·网络·c++
淡定是个好东西1 小时前
springboot连接高斯数据库(GaussDB)踩坑指南
数据库·gaussdb
追风赶月、1 小时前
【Redis】哨兵(Sentinel)机制
数据库·redis·sentinel
***似水流年***1 小时前
Linux任务管理与守护进程
linux·运维·服务器
悟能不能悟1 小时前
mysql的not exists走索引吗
数据库·mysql
明月与玄武1 小时前
Jmeter -- JDBC驱动连接数据库超详细指南
数据库·jmeter·配置jdbc连接
专注VB编程开发20年1 小时前
VB.NET关于接口实现与简化设计的分析,封装其他类
java·前端·数据库