C#中的Windows窗体问题 [英] Windows form problem in c#

查看:73
本文介绍了C#中的Windows窗体问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Visual Studio 2010与.NET 4.0一起使用.

在我的项目中,我有三种形式,其中两种形式具有文本框,这些文本框将被更新以向用户提供信息.当我使用hide()函数或将可见性设置为false,然后将表单带回时,所有文本框和标签都恢复为其默认值.

有什么方法可以隐藏表单,但可以使表单保留其当前状态,而不必将文本从文本框和标签转移到变量中?

I am using visual studio 2010 with .NET 4.0.

In my project I have three forms, two of them have text boxes which will be updated to provide the user with information. When I use the hide() function or set the visibility to false and then bring the form back all the text boxes and labels go back to their default values.

Is there any way to hide forms, but make them retain their current state without having to transfer the text from the text boxes and labels into variables?

推荐答案

不正确.调用Hide不能对状态执行任何操作(可见性除外).呼叫Show;甚至表单的位置/大小都一样.您当然会做其他事情导致这种混乱.

看起来,当您尝试使用真实的"开发代码时,会发生大量类似的问题.在所有这些情况下,请不要犹豫地添加与您的主代码无关的简约原型,以执行纯测试.

-SA
Not true. Calling Hide cannot do anything to the status except visibility. Call Show; and everything will be the same, even position/size of the form. You certainly do something else which causes this confusion.

Look, huge amount of problems like that happens when you experiment with your "real" development code. In all such cases do not hesitate to add a minimalistic prototype not related to your main code to perform a pure test.

—SA


您必须在重新显示表单时重新创建它.
您必须保留父表单中表单的引用,以便在向后展示时,使用具有show属性的同一对象.


you must be recreating the form while showing it back.
you must retain the reference of a form in parent form so while showing it back you use the same object with show property.
i.e.

From2 frm;

OpenForm2()
{
 if (frm == null)
   frm = new From2();
 frm.show();

}


此刻,我在单击按钮时使用此代码.

At the moment I am using this code in a button click.

Test openTest = new Test;
openTest.show();
This.hide();



为什么需要检查它是否等于null?



Why do I need to check if it is equal to null?


这篇关于C#中的Windows窗体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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