Setting programmatically closereason

后端 未结 4 625
你的背包
你的背包 2021-02-19 10:25

I want to set the CloseReason of a form after I call This.Close() inside the form.

Usually, this forms is closed by itself calling This.Close(), but I want to ask the us

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 10:41

    CloseReason is an enum with the following members:

    None
    WindowsShutDown
    MdiFormClosing
    UserClosing
    TaskManagerClosing
    FormOwnerClosing
    ApplicationExitCall
    

    Which leads me to believe that it is dependent on conditions related to the behavior of forms in general (ex. closing a parent form closes it's childs). So in order for the arg to have say, the CloseReason.ApplicationExitCall, the event must be triggered from a Application.Exit call.

    Same with say a CloseReason.FormOwnerClosing, assuming your child forms are called using form.Show(Parent)

    If your goal is to simply have extra information of why the form is closing, you can simply store it inside the form object as a public attribute or property to access it later, assuming said form wasn't disposed.

    Providing what was your motivation in changing the CloseReason would probably help, as well.

    CloseReason msdn page for reference http://msdn.microsoft.com/en-us/library/system.windows.forms.closereason.aspx

提交回复
热议问题