Disable the Close [X] Button in C#!

All tutorials created in C# to be posted in here.
5 posts Page 1 of 1
Contributors
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Disable the Close [X] Button in C#!
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!
You do not have the required permissions to view the files attached to this post.
Last edited by code it on Sun Apr 03, 2011 4:48 pm, edited 1 time in total.
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Just out of curiosity,
Do you understand the codes?
Top-notch casual Dating
User avatar
code it
VIP - Site Partner
VIP - Site Partner
Posts: 821
Joined: Sun Oct 10, 2010 3:02 pm

Since I am learning a bit and i got help a bit from a converter forgot to mention that so i will
User avatar
Skillful
Skillful Coders
Skillful Coders
Posts: 969
Joined: Tue Nov 16, 2010 10:07 am

Nice tutorial but how did you get that button with the two arrows?
Instead of LOL use this -
LSIBMHBIWFETALOL

Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

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.
Image
5 posts Page 1 of 1
Return to “C-Sharp Tutorials”