C#在另一个类中使用Winform控件 [英] C# using winform controls in another class

查看:144
本文介绍了C#在另一个类中使用Winform控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForm应用程序。在主窗体上,有许多控件,例如标签,文本框等。

I have a WinForm application. On the main form there are a number of controls, such as labels, textboxes, etc.

如果我在同一程序集中有另一个类,如何访问这些控件

If I have another class, within the same assembly, how can I access those controls?

例如,在我的新类中,我想在Form1中更新标签吗?

For example from my new class, I want to update a label in Form1?

推荐答案

在标签(或任何控件)的属性中,将修饰符选项设置为公共

In the property of the label (or any control) make the "Modifiers" option to "Public"

现在您可以访问标签了来自表单对象

Now you can access the label from the object of the Form

 Form1 f = new Form1()
 f.lblMyLabel.Text = "My Text"

这篇关于C#在另一个类中使用Winform控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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