我刚才去试了一下,可以增加这样两个事件。
private void Form1_MouseLeave(object sender, System.EventArgs e)
{
this.FormBorderStyle=FormBorderStyle.Sizable;
} private void Form1_MouseEnter(object sender, System.EventArgs e)
{
this.FormBorderStyle=FormBorderStyle.None;
}你看看。
private void Form1_MouseLeave(object sender, System.EventArgs e)
{
this.FormBorderStyle=FormBorderStyle.Sizable;
} private void Form1_MouseEnter(object sender, System.EventArgs e)
{
this.FormBorderStyle=FormBorderStyle.None;
}你看看。
1.formBorderStyle设为none之后,怎么让鼠标托动窗体?
参考:http://expert.csdn.net/Expert/topic/2938/2938210.xml?temp=.8810083
在鼠标拖动窗体时若要显示虚框,跟操作系统设置有关:
在桌面单击右键 ->属性 ->效果 把拖动时显示窗口内容 不选时有虚框出现。
2.FormBorderStyle =None的情况下如何实现拖动窗口边缘改变窗口大小
在工具箱里找到splitter控件,拖到窗体上,设置dock属性为right,name为
需要添加三个事件:
this.splitterRight.MouseUp += new System.Windows.Forms.MouseEventHandler(this.splitterRight_MouseUp);
this.splitterRight.MouseMove += new System.Windows.Forms.MouseEventHandler(this.splitterRight_MouseMove);
this.splitterRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.splitterRight_MouseDown);
private bool flagMove=false;
//左键按下时,设置可移动
private void splitterRight_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.flagMove = true;
}
//右边移动
private void splitterRight_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(this.flagMove )
{
this.Width = this.Width +e.X ;
}
}
//左键松开时,设置不可移动
private void splitterRight_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.flagMove = false;
}
3.添加三个label控件,实现最小化,最大化,关闭按钮
//最小化按钮
private void labelMin_Click(object sender, System.EventArgs e)
{
this.WindowState = FormWindowState.Minimized ;
}
//最大化及还原按钮
private void labelMax_Click(object sender, System.EventArgs e)
{
if(this.WindowState ==FormWindowState.Maximized )
{
this.WindowState = FormWindowState.Normal ;
}
else
{
this.WindowState = FormWindowState.Maximized ;
}
}
//关闭按钮
private void labelclose1_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
}4.加上你所要的背景图片即可
任务栏中还要有窗体名称: 把窗体的text设为你要的名称即可
这个方法,到是可以实现改变窗口大小 ,但是也太糙了些,和实际的窗体托动差别太大
// 鼠标离开窗体时,显示窗口的边缘
{
this.FormBorderStyle=FormBorderStyle.Sizable;
} private void Form1_MouseEnter(object sender, System.EventArgs e)
//鼠标进入窗体时隐藏标题栏和边缘.
{
this.FormBorderStyle=FormBorderStyle.None;
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace MoveControlLocation
{
/// <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 HTSIZE = 0x4;
private const int HTCAPTION = 0x2;
private const int WM_SIZING = 532;
private const int HTMINBUTTON = 8; private const int BorderWidth = 5; // m.Result = (IntPtr)20;//关闭按纽
// m.Result = (IntPtr)21;//help按纽 //可以调整窗体的大小和移动窗体的位置
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case WM_NCHITTEST:
base.WndProc(ref m);
if (DesignMode)
{
return;
} if ((int)m.Result == HTCLIENT)
if ((Cursor.Position.X<=this.Left + BorderWidth) && (Cursor.Position.Y <= this.Top + BorderWidth))
m.Result = (IntPtr)13;//左上
else if ((Cursor.Position.X>=this.Left + this.Width-BorderWidth) && (Cursor.Position.Y<=this.Top +BorderWidth))
m.Result = (IntPtr)14;//右上
else if ((Cursor.Position.X <= this.Left + BorderWidth) && (Cursor.Position.Y>=this.Top + this.Height-BorderWidth))
m.Result = (IntPtr)16;//左下
else if ((Cursor.Position.X>=this.Left + this.Width-BorderWidth) && (Cursor.Position.Y>=this.Top + this.Height-BorderWidth))
m.Result = (IntPtr)17;//右下
else if (Cursor.Position.X<=this.Left + BorderWidth)
m.Result = (IntPtr)10;//左
else if (Cursor.Position.X>=this.Left + this.Width-BorderWidth)
m.Result = (IntPtr)11;//右
else if (Cursor.Position.Y<=this.Top + BorderWidth)
m.Result = (IntPtr)12;//上
else if (Cursor.Position.Y>=this.Top + this.Height-BorderWidth)
m.Result = (IntPtr)15;//下
else
m.Result = (IntPtr)HTCAPTION;//移动窗体
return;
default:
base.WndProc(ref m);
break;
}
}
}
}