disable x button in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prokopis
    New Member
    • Nov 2007
    • 30

    disable x button in c#

    i disable the x button in the form but it also disable the EXIT button that i have create.
    the code is
    Code:
    Initialize component
    {.........
    this.Closing += new System.ComponentModel.CancelEventHandler(this.MyForm_Closing);
    }
    
    on the program
    
    private void MyForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
            {
                /// stuff
                e.Cancel = true; /// Do this if you want to keep the form alive,
                /// and just hide it or something
            }
    this that i want is to disable the x button that the form has and not the exit button that i have create
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Create a bool value something like:
    Code:
    bool AllowedToClose=false;
    Then in your exit button event handler do this:
    Code:
    AllowedToClose=true;
    this.Close();
    And in your closing event:
    Code:
    e.Cancel=!AllowedToClose;

    You should note that the "e" argument in the closing event handler also has a property that tells you what kind of closing event it is, such as "PC shutting down", or other messages.
    You should be sure to allow you program to close when the PC wants to shut down.

    Comment

    Working...