与用户交互后如何将表单重置为其默认外观 [英] How to reset a form to its default appearance, after interaction with user

查看:21
本文介绍了与用户交互后如何将表单重置为其默认外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在与用户进行一些交互后获得表单的默认视图.换句话说,在用户隐含的一些更改之后,什么命令会将表单返回到初始弹出外观?我有很多控件和计算,所以我不想一一检查控件并将它们设置为空或默认值.那就太好了,好像我再次启动表单一样,某种方式.

I wanted to get default view of my form after some interaction with user. In other words after some changes that has been implied by user, what command will return the form to the initial pop up appearance? I have many controls, and calculations, so I dont want to go over the control one by one and set them null or their default value. It would be great, as if I initate the form once more, some how.

推荐答案

您可以尝试清除表单上的控件,然后调用 InitializeComponent() 方法.

You could try clearing the controls on the form, then calling the InitializeComponent() method.

while (Controls.Count > 0)
{
    Controls[0].Dispose();
}
InitializeComponent();

另一个不会导致任何性能问题的选项是利用数据绑定.创建一个数据对象,该对象与您要重置的所有字段一一对应,然后一旦需要重置表单,只需将表单的数据源设置为数据对象的新实例.

Another Option that wouldn't cause any performance issues would be to utilize data binding. Create a data object that maps one to one with all of the fields you'd like to reset, then once it is time to reset the form simply set the data source of your form to a new instance of the data object.

这篇关于与用户交互后如何将表单重置为其默认外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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