用鼠标调整没有边框的窗体
来源:互联网 发布:录像配音乐软件 编辑:程序博客网 时间:2024/05/01 22:50
这里的代码是一个用来模拟用鼠标调整一个窗口的大小或位置的(最好是没有边的窗体),有意思啊,觉得好用好玩,拿来和大家共享下,希望高人指点,以改进程序(已修改),用这个方法也可以对Window Form Control来做,这样的话就可以在运行时可以调整你的控件的大小或位置了,注意是用WndProc实现的哟:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Size_MoveForm
{
/// <summary>
/// FormBase 的摘要说明。
/// 可以调整窗体的大小和移动窗体的位置,如需要可以从这个
/// 类继承一个新的俱有这个特性的新的窗体类或窗体实例
/// </summary>
public class FormBase : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public FormBase()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// FormBase
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(192, 146);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "FormBase";
this.Text = "FormBase";
}
#endregion
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;
private int m_CaptionHeight = 20;
private const int BorderWidth = 5;//自己定义的窗体边的宽度
//可以调整窗体的大小和移动窗体的位置
protected override void WndProc(ref Message m)
{
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;//下
else if (C_Pos.Y<=rect.Top + m_CaptionHeight + m_BorderWidth )
{
if (C_Pos.X<=rect.Left + m_BorderWidth + m_CaptionHeight)
{
m.Result = (IntPtr)HTSYSMENU;//模拟系统菜单,双击可以关闭窗体
}
else
{
m.Result = (IntPtr)HTCAPTION;//模拟标题栏,移动或双击可以最大或最小化窗体
}
}
}
return;
}
else
{
base.WndProc(ref m);
}
}
}
}
- 用鼠标调整没有边框的窗体
- 用鼠标调整没有边框的窗体
- MFC无边框的窗体实现用鼠标拖动窗体边缘实现窗体大小变化
- MFC无边框的窗体实现用鼠标拖动窗体边缘实现窗体大小变化
- MFC无边框的窗体实现用鼠标拖动窗体边缘实现窗体大小变化
- MFC无边框的窗体实现用鼠标拖动窗体边缘实现窗体大小变化
- MFC无边框的窗体实现用鼠标拖动窗体边缘实现窗体大小变化
- C# 用鼠标拖动无边框窗体
- 如何拖动没有边框的窗体?
- WinForm窗体没有系统边框的时候移动窗体
- C#无边框窗体调整大小的方法
- Winfrom窗体在去掉窗体边框的情况下使鼠标移动窗体
- delphi 无边框用鼠标改变窗体大小
- 制作没有边框的窗体,并可移动
- c#中两种方法拖动没有边框的窗体
- winform技巧—没有边框移动窗体的方法
- 没有标题栏并可以调整大小的窗体
- java swing设置窗体无边框后鼠标还能拖动窗体的方法
- delphi 的twebbrower 中支持拷贝
- The Function of MaxValue
- 对Linux系统进行配置应该养成做备份的习惯--个人总结
- Smarty教程
- oracle 优化方法
- 用鼠标调整没有边框的窗体
- “数据存储与数据系统安全”高级研修班
- 破解Win2k管理员密码 大全
- 如何在.net里实现把独立FrameSet里的Forms参数传递给另一个FrameSet里的.aspx文件。
- 常用ASP代码(一)
- 笑话中的哲理
- 调试工具系列--javascript的追踪者(tracer)实现
- perl的建树算法
- 琐事点滴