重置按钮WPF C# [英] Reset button wpf C#
本文介绍了重置按钮WPF C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以使重置按钮从头开始重新启动程序.
我使用了一个与Window_Loaded相等的命令按钮,但是我已经将一些标签转换为int32,如果我重新使用它们,程序将完全关闭.我使用了label4.Content = string.Empty;
Is there a way to make a reset button that restarts my program from the beginning.
I used a button with the commands that is equal to Window_Loaded but I have converted some labels to int32 and if I reuse them, the program shuts down completely. I used label4.Content = string.Empty;
推荐答案
哦,我看到您正在使用WPF.在这种情况下,您可以使用以下代码在单击按钮时重新启动应用程序:
Oh, I see you are using WPF. In that case, you can use the following code to restart your application on a button click:
// This will go in the event handler for your button click.
System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
我在此处找到了上面的代码,并进行了尝试自己...有效.
I found the above code here and tried it out myself... it works.
在按钮的click事件处理程序中,使用以下代码:
In the click event handler for your button, use the following code:
Application.Restart();
这篇关于重置按钮WPF C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文