【问题标题】:Restarting/Resetting program when radiobutton is selected选择单选按钮时重新启动/重置程序
【发布时间】:2014-09-16 05:51:33
【问题描述】:

我正试图弄清楚一旦从单选按钮的选项中选择了重置我的 Windows 窗体应用程序的选项。例如:。

因此,一旦选择“是”,程序就会重置。这是我一直在尝试的。

private void EndOptions() {                  

        if (anotheryes.Checked) {
            RestartForm(); 
        }

        if (anotherno.Checked) {

            //todo
        }
    }

restartform方法就是:

private void RestartForm() {
        Application.Restart();
        Application.ExitThread();
    }

现在,这只有在我再次按下“计算比率”按钮时才有效。单击后,应用程序将重新启动。我想要它,只需单击“是”单选按钮即可重置。

按钮背后的逻辑如下:

 private void DisplayLogic() {

        double height = 0, waist = 0;

        if (WaistNumericCheck(out waist) && HeightNumericCheck(out height)) { //check if input is numeric, if true, move on to next check

            if (CheckDimensionHeight(height) == true && CheckDimensionsWaist(waist) == true) { //check if dimensions are higher than the lower limits, if BOTH true, move on the next

                ShowResult(height, waist); //shows results
                DisableInputs(); //disables inputs while results are being shows
                AnotherGroupBoxVisible();//makes the restart selection groupbox visible
                EndOptions(); //check to see which option is selected                    
            }
        }
    }

任何提示/帮助将不胜感激,谢谢!

【问题讨论】:

  • 您选择了惰性选项。只需编写一些代码即可使您的应用程序处于适当的状态。如果您必须设置或重置一些变量,请执行此操作。完全重新启动应用程序只是一个技巧。

标签: c# forms application-restart


【解决方案1】:

我不得不说让整个应用程序重新启动是一件奇怪的事情,只是为了让用户可以进行另一次计算。您正在使用的 API 即 Application.Restart 已记录用于与 ClickOnce 应用程序一起使用 http://msdn.microsoft.com/en-us/library/system.windows.forms.application.restart(v=vs.110).aspx

我不知道您的应用是否点击过一次。但无论如何,希望您无论如何都能学到新的东西,这里是您问题的字面答案..

http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.checkedchanged(v=vs.110).aspx

当单选按钮的 Checked 属性值发生变化时,会发生此事件。

无论如何,我强烈建议您按照上面评论中的建议,重新考虑您希望您的应用如何在此处提供更好的用户体验。

如果只是为了学习,该事件应该会有所帮助.. 并且可以随意探索控件上可能感兴趣的其他事件。

【讨论】:

    【解决方案2】:

    处理RadioButton的CheckedChanged事件,点击后立即重启:

        private void AnotherYes_CheckedChanged(object sender, EventArgs e)
        {
            if (AnotherYes.Checked)
            {
                Application.Restart();
            }
        }
    

    http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton.checkedchanged(v=vs.110).aspx

    【讨论】:

      猜你喜欢
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      相关资源
      最近更新 更多