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;

}

}

}

相关推荐
云和数据.ChenGuang1 小时前
Django 应用安装脚本 – 如何将应用添加到 INSTALLED_APPS 设置中 原创
数据库·django·sqlite
woshilys2 小时前
sql server 查询对象的修改时间
运维·数据库·sqlserver
Hacker_LaoYi2 小时前
SQL注入的那些面试题总结
数据库·sql
建投数据3 小时前
建投数据与腾讯云数据库TDSQL完成产品兼容性互认证
数据库·腾讯云
Hacker_LaoYi4 小时前
【渗透技术总结】SQL手工注入总结
数据库·sql
岁月变迁呀4 小时前
Redis梳理
数据库·redis·缓存
独行soc4 小时前
#渗透测试#漏洞挖掘#红蓝攻防#护网#sql注入介绍06-基于子查询的SQL注入(Subquery-Based SQL Injection)
数据库·sql·安全·web安全·漏洞挖掘·hw
你的微笑,乱了夏天4 小时前
linux centos 7 安装 mongodb7
数据库·mongodb
远游客07134 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
工业甲酰苯胺5 小时前
分布式系统架构:服务容错
数据库·架构