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;

}

}

}

相关推荐
零雲21 小时前
除了缓存,我们还可以用redis做什么?
数据库·redis·缓存
cyforkk21 小时前
MySQL 唯一约束:从基础到实战,解决数据重复的核心工具
数据库·mysql
不想被吃掉氩21 小时前
MySQL的事务特性和高可用架构
数据库·oracle
万添裁21 小时前
关系模型的数据结构
数据库
道路与代码之旅21 小时前
Delphi - IndyHttpServer接收上传文件
运维·服务器
TToolss1 天前
删除文件夹里的网盘图标
windows
烦躁的大鼻嘎1 天前
【Linux】深入Linux多线程架构与高性能编程
linux·运维·服务器·开发语言·c++·ubuntu
羚羊角uou1 天前
【Linux】system V共享内存
linux·运维·服务器
「QT(C++)开发工程师」1 天前
UML | 最好的类图设计工具结合CSDN天启呈现-领路架构师
数据库·uml·类视图
Damon小智1 天前
玩转ClaudeCode:用Database-MCP实现自然语言操作数据库
数据库·ai编程·claude·vibe coding·claude code