自己的windows控件如何实现在应用时可以放大或缩小. 设计时还是运行时放大缩小?在调用窗体的Resize事件里处理代码吧this.UserControl1.size=new size(this.Width/2,this.Heigth/2); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 运行到时可以用楼上方法,如果设计要anchor就好 在你的控件上添加如下的代码,复制粘贴一下就OK了:private const int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息private const int HTCLIENT = 0x1;//工作区private const int HTSYSMENU = 3;//系统菜单private const int HTCAPTION = 0x2; //标题栏private const int HTLEFT = 10;//向左private const int HTRIGHT = 11;//向右private const int HTTOP = 12;//向上private const int HTTOPLEFT = 13;//向左上private const int HTTOPRIGHT = 14;//向右上private const int HTBOTTOM = 15;//向下private const int HTBOTTOMLEFT = 16;//向左下private const int HTBOTTOMRIGHT = 17;//向右下private int m_BorderWidth = 2;//可以调整窗体的大小和移动窗体的位置protected override void WndProc(ref Message m){ //System.Console.WriteLine(m.Msg.ToString("X")); if (m.Msg == WM_NCHITTEST) { base.WndProc(ref m); if (DesignMode) { return; } if ((int)m.Result == HTCLIENT) { m.HWnd = this.Handle; System.Drawing.Rectangle rect = this.RectangleToScreen(this.ClientRectangle); Point C_Pos = Cursor.Position; if ((Cursor.Position.X<=rect.Left + m_BorderWidth) && (C_Pos.Y <= rect.Top + m_BorderWidth)) m.Result = (IntPtr)HTTOPLEFT;//左上 else if ((C_Pos.X>=rect.Left + rect.Width-m_BorderWidth) && (C_Pos.Y<=rect.Top +m_BorderWidth)) m.Result = (IntPtr)HTTOPRIGHT;//右上 else if ((C_Pos.X <= rect.Left + m_BorderWidth) && (C_Pos.Y>=rect.Top + rect.Height-m_BorderWidth)) m.Result = (IntPtr)HTBOTTOMLEFT;//左下 else if ((C_Pos.X>=rect.Left + rect.Width-m_BorderWidth) && (C_Pos.Y>=rect.Top + rect.Height-m_BorderWidth)) m.Result = (IntPtr)HTBOTTOMRIGHT;//右下 else if (C_Pos.X<=rect.Left + m_BorderWidth-1) m.Result = (IntPtr)HTLEFT;//左 else if (C_Pos.X>=rect.Left + rect.Width-m_BorderWidth) m.Result = (IntPtr)HTRIGHT;//右 else if (C_Pos.Y<=rect.Top + m_BorderWidth-1) m.Result = (IntPtr)HTTOP;//上 else if (C_Pos.Y>=rect.Top + rect.Height-m_BorderWidth) m.Result = (IntPtr)HTBOTTOM;//下 } return; } else { base.WndProc(ref m); }} 设置控件的Anchor属性为Top,Left,Bottom,Right,控件就会自动根据窗体大小变化而变化。(只对大小能变化的控件有效,比如textbox是singleline的话,控件只会发生长度的变化) 类属性两种形式 用C#写得一个登陆界面,要求使用xml记录用户名密码!..... C#关于LISTVIEW取值的问题。 内容文字太多怎么实现翻页????? datagrid 和 datatable 定位问题 c#调用api报错,string 如何转换为IntPtr 如何统计一个字符串最多出现的字符的数量 急救!!!!!一个新手 连接数据库老出问题 如何提高C#编写的.net应用程序的性能? DateTime类型在DataGrid控件为什么只显示Date,而不显示Time!!!!!! 关于图形图像的剪切、放大缩小问题 找一个函数
private const int WM_NCHITTEST = 0x84; //移动鼠标,按住或释放鼠标时发生的系统消息
private const int HTCLIENT = 0x1;//工作区
private const int HTSYSMENU = 3;//系统菜单
private const int HTCAPTION = 0x2; //标题栏private const int HTLEFT = 10;//向左
private const int HTRIGHT = 11;//向右
private const int HTTOP = 12;//向上
private const int HTTOPLEFT = 13;//向左上
private const int HTTOPRIGHT = 14;//向右上
private const int HTBOTTOM = 15;//向下
private const int HTBOTTOMLEFT = 16;//向左下
private const int HTBOTTOMRIGHT = 17;//向右下
private int m_BorderWidth = 2;//可以调整窗体的大小和移动窗体的位置
protected override void WndProc(ref Message m)
{
//System.Console.WriteLine(m.Msg.ToString("X"));
if (m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if (DesignMode)
{
return;
}
if ((int)m.Result == HTCLIENT)
{
m.HWnd = this.Handle; System.Drawing.Rectangle rect = this.RectangleToScreen(this.ClientRectangle);
Point C_Pos = Cursor.Position; if ((Cursor.Position.X<=rect.Left + m_BorderWidth) && (C_Pos.Y <= rect.Top + m_BorderWidth))
m.Result = (IntPtr)HTTOPLEFT;//左上
else if ((C_Pos.X>=rect.Left + rect.Width-m_BorderWidth) && (C_Pos.Y<=rect.Top +m_BorderWidth))
m.Result = (IntPtr)HTTOPRIGHT;//右上
else if ((C_Pos.X <= rect.Left + m_BorderWidth) && (C_Pos.Y>=rect.Top + rect.Height-m_BorderWidth))
m.Result = (IntPtr)HTBOTTOMLEFT;//左下
else if ((C_Pos.X>=rect.Left + rect.Width-m_BorderWidth) && (C_Pos.Y>=rect.Top + rect.Height-m_BorderWidth))
m.Result = (IntPtr)HTBOTTOMRIGHT;//右下
else if (C_Pos.X<=rect.Left + m_BorderWidth-1)
m.Result = (IntPtr)HTLEFT;//左
else if (C_Pos.X>=rect.Left + rect.Width-m_BorderWidth)
m.Result = (IntPtr)HTRIGHT;//右
else if (C_Pos.Y<=rect.Top + m_BorderWidth-1)
m.Result = (IntPtr)HTTOP;//上
else if (C_Pos.Y>=rect.Top + rect.Height-m_BorderWidth)
m.Result = (IntPtr)HTBOTTOM;//下
}
return;
}
else
{
base.WndProc(ref m);
}
}
(只对大小能变化的控件有效,比如textbox是singleline的话,控件只会发生长度的变化)