Page 1 of 1

Disable the Close [X] Button in C#!

Posted: Sun Apr 03, 2011 4:10 pm
by code it
Since XTechVB did it in VB.NET I decided to convert it myself to C# AND HELP WITH CONVERTER


Create a new C# Project and double click or right click and click "View Code" to the code view!

Put this code above the public Form1()
Code: Select all
protected override CreateParams CreateParams {
	get {
		CreateParams cp = base.CreateParams;
		const int CS_NOCLOSE = 0x200;
		cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
		CS_NOCLOSE.ToString().Trim();
		return cp;
	}
}

So basically it will be:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                const int CS_NOCLOSE = 0x200;
                cp.ClassStyle = cp.ClassStyle | CS_NOCLOSE;
                CS_NOCLOSE.ToString().Trim();
                return cp;
            }
        }
        public Form1()
        {

            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

ScreenShot:
Capture.PNG

Source Project:
WindowsFormsApplication1.zip
Enjoy the C# Code!

Re: Disable the Close [X] Button in C#!

Posted: Sun Apr 03, 2011 4:44 pm
by Agust1337
Just out of curiosity,
Do you understand the codes?

Re: Disable the Close [X] Button in C#!

Posted: Sun Apr 03, 2011 4:47 pm
by code it
Since I am learning a bit and i got help a bit from a converter forgot to mention that so i will

Re: Disable the Close [X] Button in C#!

Posted: Sun Apr 03, 2011 6:46 pm
by Skillful
Nice tutorial but how did you get that button with the two arrows?

Re: Disable the Close [X] Button in C#!

Posted: Sun Apr 03, 2011 6:48 pm
by Scottie1972
CoderBoy1201 wrote:
Nice tutorial but how did you get that button with the two arrows?
That button is created by TeamVeiwer.
It is a control button.