EFileTahi-A Posted July 21, 2005 Posted July 21, 2005 How can I enable / disable the close button of a form through code? Quote
thenerd Posted July 21, 2005 Posted July 21, 2005 Lots of ways, In the form_closing sub, set e.canceled to true Remove the form's border ...Ok, two ways. Quote
jmcilhinney Posted July 22, 2005 Posted July 22, 2005 Set the ControlBox property to False to remove icon, system menu and buttons from the title bar. I'm pretty sure there is no way to actually disable that button, i.e. have it be there but "greyed out", in .NET. You need to either get rid of it, which is a bit of a baby and bath water situation, or determine whether it was clicked and act accordingly. You can set a variable when a legal closing method is used and set e.cancelled to True in the form's Closing event handler if that variable is not set. You can also intercept the Windows Message that is sent when that button is clicked using the by overriding the WndProc method. I can't remember what the message is but I've seen mention of it several times in several different places. Quote
Wile Posted July 22, 2005 Posted July 22, 2005 I'm pretty sure there is no way to actually disable that button' date=' i.e. have it be there but "greyed out", in .NET. [/quote'] .NET no, using some old win32 methods it should be possible. I've done it in a VB5 application although that was such a long time ago that I dont remember the exact details ;). Bit of googling and msdning: http://support.microsoft.com/?kbid=245746 this is for an access database, but they dont use access methods (access doesnt support disabling the close button either) but they use win32 functions. This means you should be able to use this solution in .net as well. Quote Nothing is as illusive as 'the last bug'.
EFileTahi-A Posted July 25, 2005 Author Posted July 25, 2005 Ok buddies, it is done. Thank you all :) - THREAD CLOSED - Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.