Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[Snippet] Disable Close [X] Button

I was looking for something like this, and found it. So, i thought i would share it with anyone else needing it.

Code
Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overrides ReadOnly Property CreateParams() As CreateParams
    Get
        Dim myCp As CreateParams = MyBase.CreateParams
        myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
        Return myCp
    End Get
End Property

All you do is paste that into your form. Works perfectly.

Of course you could probably use this for some sort of malicious purpose but i was using it so they would have to Right Click > Exit instead of just being able to close the form. (There's a reason behind it.)

Have fun!

Spoiler (Click to View)
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
Can't they go to task manager and end it from there? Or will it reopen again?
Pretty nice but I'd rather just

PHP Code

<?php 
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    e
.Cancel = True
    End Sub 
(Mar 3, 2012 09:45 AM)Marketplace Wrote:  Can't they go to task manager and end it from there? Or will it reopen again?

This doesn't stop your application from closing, it's disables the close button. Yes, they can open up task manager and it will close it if they click end.
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
(Mar 3, 2012 09:55 AM)SomeWhiteGuy Wrote:  This doesn't stop your application from closing, it's disables the close button. Yes, they can open up task manager and it will close it if they click end.

Either way, pretty good stuff here, good job.
You could also just disable the ControlBox property on the form, although that would cause the icon to disappear as well.
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
(Mar 3, 2012 12:07 PM)idb. Wrote:  You could also just disable the ControlBox property on the form, although that would cause the icon to disappear as well.

That causes all icons to disappear. I wanted to keep the minimize and maximize buttons. But yes, you are correct.
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
Thanks for this man, I was always wondering how to do that 🙂
Does it make the button grayed out or just disable it but still make it clickable?
THE POSTER PREVIOUSLY KNOWN AS SAINT LAURENT PARIS
(Mar 3, 2012 01:16 PM)Raf Simons Wrote:  Does it make the button grayed out or just disable it but still make it clickable?

It disables it, like if you disable the maximize button it would look like that.

[img]http://imgs.ps3-forums.net/xboxmb/vWeDeDIgVGaLxcQLUwFW.png[/img]
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
It's more sleek-looking than some other solutions :p Nice find.
Thanks very much for this snippet, OP. I've implemented it in my program, expect to see your name in there.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by еlixirSep 9, 2022 06:31 AM 0 132 Sep 9, 2022 06:31 AM
Last Post: еlixir
[Python] by datguy.devNov 28, 2019 10:37 PM 4 296 Nov 28, 2019 10:37 PM
Last Post: Eternal Darkness
[.NET] by LeonieHackPetaBytes2Jan 23, 2019 05:10 PM 1 227 Jan 23, 2019 05:10 PM
Last Post: 0xDEAD10CC