从任何可用的表单C#中读取表单值 [英] Reading form values from any available form C#

查看:77
本文介绍了从任何可用的表单C#中读取表单值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主表单,凭据表单和其他表格需要访问凭证表单中的数据



凭证表单将在每次运行时访问一次,基本上主要表单加载然后你单击初始化连接,它将在填充值后显示凭证表单,然后单击确定将值移动到/可以从主表单中读取。



问题是我需要Credentials Form中的数据以其他形式提供,如果使用的话可以在以后访问。



我能够得到将值输入Main表单但是我在其他表单上收到null,有没有办法让这些值可用于任何表单?是给你建议一个解决方案



谢谢



我试过的:



它现在有效,但我只能获取主窗体的值,所有其他窗体从这个窗体中获取空值,我尝试了多个是但我只能得到一个表格的值,当关闭凭证表格时,主表格和其他表格读取的值。

I have a Main form, Credential Form and other Forms that need to access the data in Credential Form

Credential form will be accessed once in each application run, Basically the main forms loads then you click on Initialize connection which will show the Credentials Form after filling the values and clicking OK the values are moved to / can be read from Main form.

The problem is that i need the data from Credentials Form to be available in other forms which can be accessed later on if used.

I was able to get the values into the Main form however i am receiving null on the other forms, is there a way to have these values available for any form ? is for can you suggest a solution

Thank you

What I have tried:

It work now but i am only able to get the value to the main form, all other forms receive null value from this form, I tried multiple was but i was only able to get the values to one form, when closing Credentials form the values are read by Main Form and non other.

推荐答案

你不想要从Credential表单获取数据的其他表单 - 他们不应该知道表单存在,更不用说数据来自哪里了!

相反,使用主表单显示凭据表单,并将值读入主窗体。

然后,当主窗体创建其他窗体时,它会通过重载的窗体构造函数或新窗体中的属性将信息传递给它们。

这样,表单可以获取所需的信息,而无需了解任何其他表单或信息的来源。
You don't want the other forms to get the data from the Credential form - they shouldn't know the form exists, much less that that is where the data comes from!
Instead, use your main form to show the Credential form, and read the values into the Main form.
Then, when the main form creates other forms, it passes the information to them, either via an overloaded form Constructor, or via properties in the new form.
That way, the form gets the info it needs without needing to know about any other forms, or where information comes from.


这篇关于从任何可用的表单C#中读取表单值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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