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;

}

}

}

相关推荐
plmm烟酒僧41 分钟前
Windows下QT调用MinGW编译的OpenCV
开发语言·windows·qt·opencv
EricWang13581 小时前
[OS] 项目三-2-proc.c: exit(int status)
服务器·c语言·前端
时差9531 小时前
【面试题】Hive 查询:如何查找用户连续三天登录的记录
大数据·数据库·hive·sql·面试·database
让学习成为一种生活方式1 小时前
R包下载太慢安装中止的解决策略-R语言003
java·数据库·r语言
算法与编程之美1 小时前
文件的写入与读取
linux·运维·服务器
秋意钟1 小时前
MySQL日期类型选择建议
数据库·mysql
Dxy12393102162 小时前
python下载pdf
数据库·python·pdf
JaneJiazhao3 小时前
HTTPSOK:SSL/TLS证书自动续期工具
服务器·网络协议·ssl
桀桀桀桀桀桀3 小时前
数据库中的用户管理和权限管理
数据库·mysql
萨格拉斯救世主3 小时前
戴尔R930服务器增加 Intel X710-DA2双万兆光口含模块
运维·服务器