简体   繁体   English

如果DialogResult确定,则关闭父窗口

[英]Close parent window if DialogResult is OK

Currently i am writing an application that has a window that confirms if the user is done editing the data and let them leave a comment on the edit. 目前,我正在编写一个具有窗口的应用程序,该窗口可确认用户是否已完成数据编辑并让他们在编辑中留下评论。 The user can confirm or cancel the edit. 用户可以确认或取消编辑。 I want to close the parent form when the child form Dialog Result is OK and refresh the data if it was canceled. 我想在子表单对话框结果确定后关闭父表单,并在取消后刷新数据。 The Result is passed correctly, still it does not close the parent form. 结果正确传递,但仍未关闭父窗体。

I used ds.FormClose on other views to run the refres. 我在其他视图上使用ds.FormClose运行引用。

I am opening a child form whit the following code. 我用下面的代码打开一个子窗体。

        View ds = new View ();
        ds.userID = userID;
        ds.localID= localID;

        ds.FormClosed += ChildFormClosed; // i use this line to call a function when the child form is close 

        DialogResult dialogResult = new DialogResult(); // fetches the Dialog Result 
        dialogResult = ds.ShowDialog(); // opens the view 

        if (dialogResult != DialogResult.OK) // checks if the Dialog Result is OK
            this.Close();
if (dialogResult != DialogResult.OK) // checks if the Dialog Result is OK

No, it does not check the dialog result is OK , it checks if it is not OK . 不,它不检查的对话框结果是OK ,它会检查,如果它是不 OK

This does: 这样做:

if (dialogResult == DialogResult.OK)

It seems to me you can't close the main Form and open a child Form. 在我看来,您无法关闭主窗体并打开子窗体。

If the main Form is close, the application is close and the program can't open a new child Form. 如果主窗体已关闭,则应用程序已关闭,程序无法打开新的子窗体。

Maybe that that has no report. 也许那没有报告。

Sorry for my English. 对不起我的英语不好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM