• <tfoot id='YYhAT'></tfoot>
  • <legend id='YYhAT'><style id='YYhAT'><dir id='YYhAT'><q id='YYhAT'></q></dir></style></legend>

    <small id='YYhAT'></small><noframes id='YYhAT'>

      <bdo id='YYhAT'></bdo><ul id='YYhAT'></ul>

      1. <i id='YYhAT'><tr id='YYhAT'><dt id='YYhAT'><q id='YYhAT'><span id='YYhAT'><b id='YYhAT'><form id='YYhAT'><ins id='YYhAT'></ins><ul id='YYhAT'></ul><sub id='YYhAT'></sub></form><legend id='YYhAT'></legend><bdo id='YYhAT'><pre id='YYhAT'><center id='YYhAT'></center></pre></bdo></b><th id='YYhAT'></th></span></q></dt></tr></i><div id='YYhAT'><tfoot id='YYhAT'></tfoot><dl id='YYhAT'><fieldset id='YYhAT'></fieldset></dl></div>

      2. 是否可以重载表单的 ShowDialog 方法并返回不同的结果?

        时间:2023-10-06

      3. <small id='rurOu'></small><noframes id='rurOu'>

              <tbody id='rurOu'></tbody>
              <tfoot id='rurOu'></tfoot>
              <legend id='rurOu'><style id='rurOu'><dir id='rurOu'><q id='rurOu'></q></dir></style></legend>

            • <i id='rurOu'><tr id='rurOu'><dt id='rurOu'><q id='rurOu'><span id='rurOu'><b id='rurOu'><form id='rurOu'><ins id='rurOu'></ins><ul id='rurOu'></ul><sub id='rurOu'></sub></form><legend id='rurOu'></legend><bdo id='rurOu'><pre id='rurOu'><center id='rurOu'></center></pre></bdo></b><th id='rurOu'></th></span></q></dt></tr></i><div id='rurOu'><tfoot id='rurOu'></tfoot><dl id='rurOu'><fieldset id='rurOu'></fieldset></dl></div>

                • <bdo id='rurOu'></bdo><ul id='rurOu'></ul>
                  本文介绍了是否可以重载表单的 ShowDialog 方法并返回不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这种方法实际上效果很好,我问了它,然后找到了解决方案.我在重载的 ShowDialog() 方法中添加了正确的调用(它不是完全重载,甚至不是覆盖,但它的工作原理相同.我的新问题是底部的问题.

                  我有一个表单,您可以在其中单击三个按钮之一.我为返回的结果定义了一个枚举.我想打电话:

                  I have a form in which you click one of three buttons. I have defined an enum for the returned results. I want to make the call:

                  MyFormResults res = MyForm.ShowDialog();
                  

                  我可以用这段代码添加一个新的 ShowDialog 方法:

                  I can add a new ShowDialog method with this code:

                  public new MyFormResults ShowDialog()
                  {
                      //Show modal dialog
                      base.ShowDialog(); //This works and somehow I missed this
                  
                      return  myResult; //Form level variable (read on)
                  }
                  

                  我为单击按钮时的结果设置了一个表单级变量:

                  I set a form-level variable for the result when the buttons are clicked:

                  MyFormResults myResult;
                  
                  private void btn1_click(object sender, EventArgs e)
                  {
                      myResult = MyFormsResults.Result1;
                      this.DialogResult = DialogResult.OK; //Do I need this for the original ShowDialog() call?
                      this.Close(); //Should I close the dialog here or in my new ShowDialog() function?
                  }
                  
                  //Same as above for the other results
                  

                  我唯一缺少的是显示对话框(模式)然后返回结果的代码.没有base.ShowDialog()函数,我该怎么做呢?

                  The only thing I'm missing is the code to show the dialog (modal) and then return my result. There is no base.ShowDialog() function, so how do I do this?

                  有一个base.ShowDialog()",它可以工作.这是我的新问题:

                  另外,这是做这一切的最佳方式吗?为什么?

                  Also, is this the best way to do all this and Why?

                  谢谢.

                  推荐答案

                  更改 ShowDialog() 的功能可能不是一个好主意,人们希望它返回一个 DialogResult 并显示表单,我建议如下我的建议.因此,仍然允许 ShowDialog() 以正常方式使用.

                  It's proberly not a good idea to change the functionality of ShowDialog(), people expect it to return a DialogResult and show the form, I suggest something like my suggestion below. Thus, still allowing ShowDialog() to be used the normal manner.

                  您可以在 MyForm 上创建一个静态方法,例如 DoShowGetResult()

                  You could create a static method on your MyForm, something like DoShowGetResult()

                  看起来像这样

                  public static MyResultsForm DoShowGetResult()
                  {
                     var f = new MyForm();
                     if(f.ShowDialog() == DialogResult.OK)
                     {
                        return f.Result;   // public property on your form of the result selected
                     }
                     return null;
                  }
                  

                  那你就可以用这个了

                  MyFormsResult result = MyForm.DoShowGetResult();
                  

                  这篇关于是否可以重载表单的 ShowDialog 方法并返回不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:完全模态 WPF 窗口? 下一篇:如何在WPF中单击菜单项时在父窗口下打开子窗口?

                  相关文章

                    <bdo id='YqFiy'></bdo><ul id='YqFiy'></ul>

                • <i id='YqFiy'><tr id='YqFiy'><dt id='YqFiy'><q id='YqFiy'><span id='YqFiy'><b id='YqFiy'><form id='YqFiy'><ins id='YqFiy'></ins><ul id='YqFiy'></ul><sub id='YqFiy'></sub></form><legend id='YqFiy'></legend><bdo id='YqFiy'><pre id='YqFiy'><center id='YqFiy'></center></pre></bdo></b><th id='YqFiy'></th></span></q></dt></tr></i><div id='YqFiy'><tfoot id='YqFiy'></tfoot><dl id='YqFiy'><fieldset id='YqFiy'></fieldset></dl></div>
                • <tfoot id='YqFiy'></tfoot><legend id='YqFiy'><style id='YqFiy'><dir id='YqFiy'><q id='YqFiy'></q></dir></style></legend>

                      <small id='YqFiy'></small><noframes id='YqFiy'>