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;

}

}

}

相关推荐
ITHAOGE151 天前
下载 | Win11 官方精简版,系统占用空间极少!(12月更新、Win 11 IoT物联网 LTSC版、适合老电脑安装使用)
windows·科技·物联网·microsoft·微软·电脑
大猫和小黄1 天前
若依微服务全面适配PostgreSQL-OpenGauss数据库
数据库·微服务·postgresql·若依
老徐电商数据笔记1 天前
技术复盘第二篇:电商数据主题域划分企业级实践
大数据·数据库·数据仓库·零售·教育电商·技术面试
jfqqqqq1 天前
postgres查询、重设自增序列的起始值
数据库·sql·postgres·自增序列
杰克崔1 天前
进程内mmap锁相互干扰问题
linux·运维·服务器·车载系统
木泽八1 天前
python实现pdf拆分与合并
服务器·python·pdf
1 天前
TIDB——PD(placement Driver)
java·数据库·分布式·tidb·
DemonAvenger1 天前
Redis与MySQL双剑合璧:缓存更新策略与数据一致性保障
数据库·redis·性能优化
断春风1 天前
如何避免 MySQL 死锁?——从原理到实战的系统性解决方案
数据库·mysql
闲人编程1 天前
基础设施即代码(IaC)工具比较:Pulumi vs Terraform
java·数据库·terraform·iac·codecapsule·pulumi