Click here to Skip to main content
15,915,509 members
Home / Discussions / C#
   

C#

 
Questionhow to write auto running program with c# Pin
yellowstone21-Feb-08 17:09
yellowstone21-Feb-08 17:09 
GeneralRe: how to write auto running program with c# Pin
Christian Graus21-Feb-08 18:27
protectorChristian Graus21-Feb-08 18:27 
GeneralDisabling of Close Form option Pin
Neo Andreson21-Feb-08 16:19
Neo Andreson21-Feb-08 16:19 
GeneralRe: Disabling of Close Form option Pin
PIEBALDconsult21-Feb-08 16:24
mvePIEBALDconsult21-Feb-08 16:24 
GeneralRe: Disabling of Close Form option Pin
Christian Graus21-Feb-08 16:30
protectorChristian Graus21-Feb-08 16:30 
GeneralRe: Disabling of Close Form option Pin
Neo Andreson21-Feb-08 16:33
Neo Andreson21-Feb-08 16:33 
GeneralRe: Disabling of Close Form option Pin
Christian Graus21-Feb-08 16:54
protectorChristian Graus21-Feb-08 16:54 
GeneralRe: Disabling of Close Form option [modified] Pin
DaveyM6921-Feb-08 23:24
professionalDaveyM6921-Feb-08 23:24 
Removing the control box gets rid of minimize and maximize too.

This method just disables the close button and the Close menu item in the form's context menu. Make sure that you give the user a clean way to close the form though!
public Form1()
        {
            InitializeComponent();
            EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
        }
        private const int SC_CLOSE = 0xf060;
        private const int MF_GRAYED = 0x0001;
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern int EnableMenuItem(IntPtr hMenu, int uIDEnableItem, int uEnable);


Edit: I should add - to enable it again if you need to declare this constant:
private const int MF_ENABLED = 0x0000;

and the code to perform the enable is:
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_ENABLED);


Dave

modified on Friday, February 22, 2008 6:14 AM

GeneralRe: Disabling of Close Form option Pin
PIEBALDconsult24-Feb-08 15:58
mvePIEBALDconsult24-Feb-08 15:58 
GeneralRe: Disabling of Close Form option Pin
DaveyM6925-Feb-08 1:05
professionalDaveyM6925-Feb-08 1:05 
GeneralRe: Disabling of Close Form option Pin
PIEBALDconsult28-Mar-08 6:27
mvePIEBALDconsult28-Mar-08 6:27 
NewsCodeForms Lite v4.0 Released (FREEWARE) Pin
Rafael Agundis21-Feb-08 15:24
Rafael Agundis21-Feb-08 15:24 
GeneralRe: CodeForms Lite v4.0 Released (FREEWARE) Pin
Christian Graus21-Feb-08 16:13
protectorChristian Graus21-Feb-08 16:13 
GeneralCombo Box slected index changed Pin
msx2321-Feb-08 11:57
msx2321-Feb-08 11:57 
GeneralRe: Combo Box slected index changed Pin
Christian Graus21-Feb-08 12:39
protectorChristian Graus21-Feb-08 12:39 
GeneralRe: Combo Box slected index changed Pin
darkelv21-Feb-08 13:06
darkelv21-Feb-08 13:06 
GeneralRe: Combo Box slected index changed Pin
DaveyM6921-Feb-08 23:36
professionalDaveyM6921-Feb-08 23:36 
GeneralObject Serialization Pin
geekfromindia21-Feb-08 8:09
geekfromindia21-Feb-08 8:09 
GeneralRe: Object Serialization Pin
TheGreatAndPowerfulOz21-Feb-08 8:26
TheGreatAndPowerfulOz21-Feb-08 8:26 
GeneralRe: Object Serialization Pin
geekfromindia21-Feb-08 8:52
geekfromindia21-Feb-08 8:52 
GeneralRe: Object Serialization Pin
TheGreatAndPowerfulOz21-Feb-08 9:18
TheGreatAndPowerfulOz21-Feb-08 9:18 
GeneralRe: Object Serialization Pin
Not Active21-Feb-08 9:22
mentorNot Active21-Feb-08 9:22 
GeneralVery weird kernel32 memory reading results. Pin
Jitse21-Feb-08 7:05
Jitse21-Feb-08 7:05 
GeneralRe: Very weird kernel32 memory reading results. Pin
TheGreatAndPowerfulOz21-Feb-08 8:44
TheGreatAndPowerfulOz21-Feb-08 8:44 
GeneralRe: Very weird kernel32 memory reading results. Pin
Jitse21-Feb-08 10:03
Jitse21-Feb-08 10:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.