winform怎么设置禁用关闭按钮? 可以最小化,但不允许最大化和关闭。任务栏右击也没有关闭选项的

如题所述

第1个回答  2014-03-15
this.MaximizeBox = false;
this.ControlBox = false;追问

我本来就设置ControlBox = false,可是一设置,那三个按钮都没了啊

我还要最小化按钮

追答

this.MaximizeBox = false;
this.MinimizeBox = true;
this.ControlBox = true;
然后在Form1的关闭事件中写入以下代码:(窗体的FormClosing)
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;//拒绝关闭
}

追问

此方法,行得通,并且简单,很好

可是,最大化和关闭按钮,还在。我想要那种,没有最大化和关闭按钮,只有最小化按钮的

本回答被提问者采纳
第2个回答  2018-08-31
需要利用Win32Api的SetWindowLong来单独禁用关闭按钮
第3个回答  2014-03-18

自己做窗标题栏

首先

  [DllImport("User32.dll", EntryPoint = "ReleaseCapture")]

        static extern long ReleaseCapture();

        [DllImport("User32.dll", EntryPoint = "SendMessage")]

        private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        public static void move(IntPtr Hand)

        {

            ReleaseCapture();

            SendMessage(Hand, 161, 2, 0);

        }

//移动窗口API
//标题栏 lable1
private void label1_MouseDown(object sender, MouseEventArgs e)//鼠标按下移动窗口
        {
            move(this.Handle);
           
        }
       label1.Text = "   "+this.Text;//标题栏文字=窗口文字
        pictureBox1.Image = Image.FromHbitmap(this.Icon.ToBitmap().GetHbitmap());//标题栏图标=窗口原来的图标
 protected override void OnClosing(CancelEventArgs e)//取消窗口关闭事件
        {
            e.Cancel = true;
            base.OnClosing(e);
        }
   private void button1_Click(object sender, EventArgs e)//最小化按钮
        {

            this.WindowState = FormWindowState.Minimized; 

        }

相似回答