Windows应用程序中的全局变量 [英] Global Variable in windows Application

查看:101
本文介绍了Windows应用程序中的全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以一种形式输入文本框的值我想以另一种形式使用该值,因此全局变量将被使用或任何其他选项请告诉我!!!!!

解决方案

注意:由于这里的其他帖子中有代码解决方案的链接,我将在这里回复更多教育者的角色,而不是这里有一些代码的角色。为什么?因为我只是觉得这样:)



用于在课程/表格之间进行交流的最佳策略应该基于正在传达的何时/经常沟通必须发生。



一种情况......称之为随机访问......当一个表格需要不时访问另一个表格上的一个字段时,该表格的访问独立其他表格中的任何事件。



另一种情况......称之为更新通知......当每次某物的价值发生变化时,需要通知其他表格。



所有场景共同的共同点是需要将一个表格中的某些内容暴露到另一个表格......另一种说法是:启用访问权限。并且,有几种方法可以做到这一点,这些方法记录在您问题的其他回复中的链接中。



如果一个表单创建另一个表单,则创建表单具有对其创建的表单的有效引用,因此,在创建的表单上公开事物相对容易。在其他情况下,如果两个表单都可以由第三个表单创建,则需要不同的技术。



并且,是的,您可以使用静态字段来公开对象/类.NET中的实例,相当于全局变量。请注意,有些人几乎有宗教的感觉,全局变量并不是一件好事,应该避免。



我建议你添加到你原来的帖子一个明确的确切地说明您的表单何时需要访问另一个表单上的TextBox,并清楚地说明需要访问的表单是否也是创建第二个表单实例的表单...如果没有,则描述创建两个表单的内容。


检查:

在表单之间传递数据 [ ^ ]

http:// msdn.microsoft.com/en-us/library/aa288422%28v=vs.71%29.aspx [ ^ ]


看看此处 [ ^ ]!



我建议你阅读这些:

3.7范围(C#) [ ^ ]

< a href =http://msdn.microsoft.com/en-us/library/0f66670z.aspx>传递参数(C#编程指南) [ ^ ]

在开始时创建线程并传递数据 [ ^ ]

接口(C#编程指南) [ ^ ]

Hi,

The Value entered of a text box in one form I want to use that value in another form so global varible will be use or any other option please let me know !!!!!

解决方案

Note: since there are links to code solutions in the other posts here, I am going to respond here in more of an educator role, than a "here's some code" role. Why ? Because I just feel like it :)

The best strategy to use for communicating between Classes/Forms should be based on what is being communicated, and when/how-often the communication must take place.

One scenario ... call it "random access" ... is when a Form needs to access a field on another Form from time to time, and that access is independent of any event in the other Form.

Another scenario ... call it "update notification" ... is when every time the value of something changes in one Form another Form needs to be notified.

What all scenarios share in common is the need to "expose" something in one Form to another Form ... another way to say that is: "enable access;" and, there are several ways to do this which are documented in the links in other responses to your question.

In the case that one Form creates another Form, the creating Form has a valid reference to the Form it creates, and, thus, exposing things on the created Form is relatively easy. In other cases, where both Forms may be created by a third Form, different techniques are required.

And, yes, you can use static fields to expose objects/class-instances in .NET which is the equivalent of "global variables." Note that some people have almost "religious" feelings that global variables are not a good thing, and should be avoided.

I recommend you add to your original post a clear statement of exactly when your Form needs access to the TextBox on the other Form, and clearly state whether the Form that needs access also is the Form that creates the instance of the second Form ... if not, then describe what creates both Forms.


Check This:
Passing Data Between Forms[^]
http://msdn.microsoft.com/en-us/library/aa288422%28v=vs.71%29.aspx[^]


Have a look here[^]!

I would suggest you to read these:
3.7 Scopes (C#)[^]
Passing Parameters (C# Programming Guide)[^]
Creating Threads and Passing Data at Start Time[^]
Interfaces (C# Programming Guide)[^]


这篇关于Windows应用程序中的全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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