Resetting all fields to initial state in C#.NET WinForms application

泪湿孤枕 提交于 2020-01-17 12:27:08

问题


got a very simple question which I can't seem to find any answer for.

In a standard WinForms application, is there anything I can iterate through in order to find all the relevant input items to reset in a given form?

EG, iterate through all inputs and set TextBox.Text = "", ComboBox.SelectedItem = -1, etc ...

If this was a Web application it'd be easy, I'd just iterate through the Controls collection in the Page. But a Console application doesn't have a Page element, and I've looked at the "this" element, and can't find any way to iterate through the inputs.


回答1:


Recursively loop through the Controls collection.




回答2:


foreach (Control ctrl in Controls)
{                
    ctrl.ResetText();
}

Control ResetText



来源:https://stackoverflow.com/questions/9845489/resetting-all-fields-to-initial-state-in-c-net-winforms-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!