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;

}

}

}

相关推荐
亲爱的非洲野猪29 分钟前
Oracle与MySQL详细对比
数据库·mysql·oracle
Matrix7032 分钟前
Navicat实现MySQL数据传输与同步完整指南
数据库·mysql
Z字小熊饼干爱吃保安1 小时前
面试技术问题总结一
数据库·面试·职场和发展
工藤新一¹1 小时前
Linux 开发工具
linux·运维·服务器
极限实验室2 小时前
一键启动:使用 start-local 脚本轻松管理 INFINI Console 与 Easysearch 本地环境
数据库·docker
W111115_2 小时前
网络综合实验
linux·运维·服务器·网络
没有口袋啦2 小时前
《数据库》第一次作业:MySQL数据库账户及授权
数据库·mysql
山川绿水2 小时前
Ubuntu22.04更新Openssh至9.9p2无法正常连接,报错解决
服务器·web安全·网络安全
古希腊数通小白(ip在学)2 小时前
HCIA实现不同vlan间的通信
linux·服务器·网络
星辰离彬2 小时前
Java 与 MySQL 性能优化:MySQL连接池参数优化与性能提升
java·服务器·数据库·后端·mysql·性能优化