尝试循环失败时如何重新加载Windows窗体 [英] How do I reload Windows form when try loop fails

查看:65
本文介绍了尝试循环失败时如何重新加载Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文本框中输入未指定的字符时出错。

因此,catch会完成其工作并且Windows窗体会自动关闭。

这里我要恢复窗口页面没有关闭。









我想用goto语句,以便它形成一个循环





I got an error when entering unspecified character in textbox.
So that catch does its work and windows forms gets closed automatically.
Here I want to resume the windows page without closing.

Or


I want to use goto statement so that it forms a loop


 static void Main()
        {
          
          
            try
            {
               
           
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
              

                Application.Run(new Form1());
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message);
//After this the program exits


                
            }
          
        }













所以我不想退出程序,而是在尝试







So I don't want to to exit the program instead the windows forms resume the previous state before try

推荐答案

试试这个



try this

}
catch (Exception exp)
{
    MessageBox.Show(exp.Message);
 Application.Run(new Form1());



}


这篇关于尝试循环失败时如何重新加载Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆