可参考链接:http://blog.csdn.net/qq_15126969/article/details/40024769
Windows自带的边框很影响我们个性化定制窗口UI的美观程序。
首选选择窗口,属性里的FormBorderStyle设置为None。边框去掉之后 会发现窗口无法最大最小化和移动。
1 在标题栏处新建三个panel,分别为标题栏,最大最小化按钮和关闭按钮
将后面几个panel设置BackgroundImage为相应图标
分别为panel_title panel_min panel_close
为panel_title添加MouseDown和MouseMove事件代码为
private Point mousePoint = new Point();
private void panel_title_MouseDown(object sender, MouseEventArgs e)
{
base.OnMouseDown(e);
this.mousePoint.X = e.X;
this.mousePoint.Y = e.Y;
}
private void panel_title_MouseMove(object sender, MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
this.Top = Control.MousePosition.Y - mousePoint.Y;
this.Left = Control.MousePosition.X - mousePoint.X;
}
}
为panel_min添加click事件
this.WindowState = FormWindowState.Minimized;
为panel_close添加close事件
private void panel4_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("是否退出?", "操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
//this.Dispose();
Application.Exit();
}
}
这样,窗口就可以拖动移动了