如何在C#Windows应用程序形式之间传递值? [英] How to pass values between forms in c# windows application?

查看:135
本文介绍了如何在C#Windows应用程序形式之间传递值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种形式A和B形式A是默认启动的应用程序的形式。
我做一些东西在A型和我转念一想运行我的B型并行再通
一个参数从表格A表格B的方法。

I have two forms A and B. Form A is the default start up form of the application. I do some stuffs in Form A and i then i want to run my Form B parallel and then pass a parameter to a method in Form B from Form A.

如何?

推荐答案

伊恩已经给一些例如code,但我想作一个更广泛的观点:

Ian has given some example code, but I'd like to make a broader point:

UI类只是类。

您将如何从一个对象将值传递给另一个对象,如果他们的没有的用户界面的一部分?你必须从一个到另一个的引用,调用一个方法或设置属性。同样的事情适用于用户界面对象。

How would you pass a value from one object to another object if they weren't part of the user interface? You'd have a reference from one to the other, and call a method or set a property. The same exact thing holds for user interface objects.

我提到这一点,因为它的东西,来了不少。每当你问自己:我怎么 X 的使用表单?试着问自己同样的问题,但与普通的老班。经常的回答将是完全一样的。

I mention this because it's something that comes up a lot. Whenever you ask yourself: "How do I do X with forms?" try asking yourself the same question but with plain old classes. Often the answer will be exactly the same.

当然还有的部分的用户界面类的差异 - 特别是与线程 - 但对于一个可怕的很多情况下,它确实帮助,如果你只是把它们当作普通类

Of course there are some differences for user interface classes - particularly with threading - but for an awful lot of cases, it really helps if you just think of them as normal classes.

这篇关于如何在C#Windows应用程序形式之间传递值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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