How can I determine whether the primary window is related?

Source: Internet
Author: User
I did not parse the closing events of the main window and the sub-window. When I was concerned with the main window, the sub-window closing events were also triggered. This is a headache for me.
But I still find a way to understand. That is, an "E. closereason" event is added to the sub-window. // Sub-window closing event
Mfmentity. formclosing + =   New Formclosingeventhandler (mfmentity_formclosing );

///   <Summary>
/// When the service is closed, a message indicating auto-saving events is displayed.
/// Scott 1, 20070828
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Static   Void Mfmentity_formclosing ( Object Sender, formclosingeventargs E)
{
//Determine whether the cursor is the Main Window Interface
Note: Determine whether the primary window is related.
If (E. closereason! =Closereason. mdiformclosing )
{
Arraylist alchanged =   New Arraylist ();
If (Mfrmmain. mdichil.pdf. Length >   0 )
{
// Determine whether the front window is fmentity
If (Mfrmmain. activemdichild Is Wincontrols. fmentity)
{
Wincontrols. fmentity fmchanged = (Wincontrols. fmentity) mfrmmain. activemdichild;
If (Fmchanged. Mode =   2 )
{
// Put the window into the arraylist, and then upload the window
Alchanged. Add (fmchanged );
}
}
}
If (Alchanged ! =   Null   && Alchanged. Count >   0 )
{
Int Iresult = Fronthelper. showexitsaveform (alchanged );
Switch (Iresult)
{
Case   1 :
// Save
Foreach (Wincontrols. fmentity In Alchanged. toarray ( Typeof (Wincontrols. fmentity )))
{
// Save data
Fronthelper. savedata ();
}
Break ;
Case   - 1 :
// Don't save
Break ;
Case   0 :
// Cancel
E. Cancel =   True ;
Break ;
Default :
// Save
Break ;
}
}
}
}

Parameter type of the closereason Column

member name description
applicationexitcall An exit method similar to the (invoke) application is called.
formownerclosing the ticket is being closed.
mdiformclosing the parent table of the multiple file interface (MDI) table is being reviewed.
none the reason for the relationship is not yet clarified or cannot be determined.
taskmanagerclosing Microsoft Windows administrators are shutting down applications.
userclosing the user is reading the user interface (UI) related table, for example, click [] in the window of the table, select [] in the "" window, or click
Alt + F4.
windowsshutdown the operating system is shutting down all applications before the host is shut down.
/// <Summary>
/// Main Window closing event
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Private   Void Fmmain_formclosing ( Object Sender, formclosingeventargs E)
{
If ( This . Mdichil.pdf. Length >   0 )
{
Arraylist alchanged =   New Arraylist ();
For ( Int Iform =   0 ; Iform <   This . Mdichil.pdf. length; iform ++ )
{
If ( This . Mdichil1_[ iform] Is Wincontrols. fmentity)
{
Wincontrols. fmentity fmchanged = (Wincontrols. fmentity) This . Mdichil1_[ iform];
If (Fmchanged. Mode =   2 )
{
Alchanged. Add (fmchanged );
}
}
}
If (Alchanged ! =   Null   && Alchanged. Count >   0 )
{
Int Iresult = Fronthelper. showexitsaveform (alchanged );
Switch (Iresult)
{
Case   1 :
// Save
Foreach (Wincontrols. fmentity In Alchanged. toarray ( Typeof (Wincontrols. fmentity )))
{
Fronthelper. savedata ();
}
Break ;
Case   - 1 :
// Don't save
Break ;
Case   0 :
// Cancel
E. Cancel =   True ;
Break ;
Default :
// Save
Break ;
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.