设置成无边框窗体即可.formBorderStyle设置为false。如果要用到最大化,最小化,关闭功能的话,自己再添加几个按钮就得了!

 

 

 

设置窗体不可以拉大你可以设置FormBorderStyle =FixedSingle 或 FixedToolWindow,不过可以拖动窗体...要想窗体不可以拖动...只能设置FormBorderStyle = none了

 

 

 

++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++

++++++++++++++++++++++++++++++++++++++++++++++
 

 

去掉边框
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
实现最大最小关闭
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();          
}

private void btnMin_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}    

private void btnMax_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
}
else
{
this.FormBorderStyle = FormBorderStyle.None;
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
this.WindowState = FormWindowState.Maximized;
}
}
因为无边框后,winform无法拖动,实现拖动
-----首先在类内创建两个成员变量
private Point mouseOffset; //记录鼠标指针的坐标
private bool isMouseDown = false; //记录鼠标按键是否按下


///---------------添加三个关于鼠标的事件
private void form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
int xOffset;
int yOffset;

if (e.Button == MouseButtons.Left)
{
xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
yOffset = -e.Y - SystemInformation.CaptionHeight -
SystemInformation.FrameBorderSize.Height;
mouseOffset = new Point(xOffset, yOffset);
isMouseDown = true;
}
}

private void form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isMouseDown)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouseOffset.X, mouseOffset.Y);
Location = mousePos;
}
}

private void form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// 修改鼠标状态isMouseDown的值
// 确保只有鼠标左键按下并移动时,才移动窗体
if (e.Button == MouseButtons.Left)
{
isMouseDown = false;
}
}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
     if (result == DialogResult.Yes)
     {
         e.Cancel = false;
         Application.Exit();
     }
     else
     {
         e.Cancel = true;
         this.Hide();
         this.Visible = false;
     }
}

private void ConExit_Click(object sender, EventArgs e)
{
     result=MessageBox.Show("确认退出系统?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
     Application.Exit();
}

【hbxtlhx】:
你一定要在如下的方法里添加参数来标识是不是应该真的退出程序:
private void   Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{   
     if (!this.m_allowExit)
     {
         this.WindowState = FormWindowState.Minimized;
         e.Cancel = true;           
     }
}

然后在弹出的菜单的Click事件里设置这个this.m_allowExit=true;
这样窗口就会顺利的关闭了.

【txwd0033】:
Application.Exit(true);行不?
如果不行的话设置一个变量,在formClosing中根据变量的值来设置e。Cancel的值

 

【hbxtlhx】:
在程序开始的时候设置this.m_allowExit=false,只有在菜单的退出事件代码里设置这个this.m_allowExit=true;就可以了.具体看你的思路了.

【lxcnn】:
可以加个全局变量判断一下是由哪里触发Closing事件,如果是关闭按钮就最小化,是右键菜单就关闭

【liutaoyue】:
/// <summary>
/// 重写窗体关闭事件
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_CLOSE = 0xF060;
if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
{
this.Hide();
return;
}
base.WndProc (ref m);
}

【bejon】:
点x和使用菜单关闭程序执行不同程序

你只要在菜单那多设一个变量加以区分就OK了

 

 

 

 

posted on 2011-04-14 20:34  钱途无梁  阅读(8784)  评论(0编辑  收藏  举报