重置一个WinForm的元素初始化状态(C#/。NET) [英] Resetting a winform's elements to initialized state (C#/.Net)

查看:279
本文介绍了重置一个WinForm的元素初始化状态(C#/。NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建在C#中使用的面板开始时要么看不见,禁用或设置为null(标签,组合框,网格等)各种元素一个WinForm。作为用户经过和使选择,这些元素被填充,选择等

I'm building a winform in C# with various elements in a panel that start out either invisible, disabled, or set to null (labels, combo boxes, grids, etc.). As the user goes through and makes choices, these elements are populated, selected, etc.

的想法是上传文件,读取它们,并处理记录到数据库中。一旦该目录的处理已完成,我希望能够让用户选择其他目录,而无需退出并重新启动winform应用程序,由pressing一个按钮,当程序完成时变得可见。

The idea is to upload files, read them, and process entries to a database. Once the processing for this directory has completed, I'd like to be able to have the user select another directory without exiting and restarting the winform app, by pressing a button that becomes visible when the process has completed.

有一个简单的调用重置应用程序(或包含内容的面板),类似于当Web窗体被刷新,或者我必须写一个函数,重置全部出这些元素之一?

Is there an easy call to reset the application (or the panel that contains the elements), similar to when a webform is refreshed, or do I have to write a function that "resets" all of those elements one at a time?

编辑:作为一个发展会议的结果,我的项目已经改变了方向。我感谢你们两个谁的答案帮助,并打算关闭的问题。

As the result of a development meeting, my project has changed direction. I thank the two of you who helped with answers, and am going to close the question.

推荐答案

简单remove从形式面板并创建新的。

Simple remove panel from the form and create the new one.

编辑:
示例:

Panel CreatePanelWithDynamicControls() {
    Panel ret = new Panel();
    ret.Dock = DockStyle.Fill;
    // some logic, which initialize content of panel

    return ret;
}

void InitializeDynamicControls() {
    this.Controls.Clear();
    Panel pnl = this.CreatePanelWithDynamiControls();
    this.Controls.Add( pnl );
}

void Form1_Load( object sender, EventArgs e ) {
    if ( !this.DesignMode ) {
        this.InitializeDynamicControls();
    }
}

// I don't know exactly, on which situation
// do you want reset controls
void SomeEvent( object sender, EventArgs e ) {
    this.InitializeDynamicControls();
}

这篇关于重置一个WinForm的元素初始化状态(C#/。NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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