从工作区中的另一个类访问 TextBox [英] Access a TextBox from another class in workspace

查看:18
本文介绍了从工作区中的另一个类访问 TextBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用一个 textBox,它位于我的其他类的主表单 Form1 上.在 Form1 类中,我可以使用:

I want to use a textBox, which is on my main form Form1 from other class. In class Form1 I can use:

    this.Invoke(new EventHandler(displayText));

and then

    private void displayAccFields(object o, EventArgs e)
    {
        tbAccRoll.AppendText(packParameters.getPackage(3) + "");
    }

而且它工作正常.

如何访问此 textbox 以显示来自不同类的内容?

How can I access this textbox for displaying something from a different class?

推荐答案

对于在两个表单之间发送值,您可以

For sending values between two forms, you may

  1. 在第二种形式的构造函数中发送值.您可以创建一个参数化的构造函数并在初始化表单时发送值.
  2. 您可以在第二个表单中引用您的第一个表单.

第二种形式,

public Form1 objForm1;

在第一形式中,

Form2 objForm2=new Form2();
Form2.objForm1=this;

然后你可以使用Form2的objForm1来引用Form1的文本框.

and then you can use Form2's objForm1 to refer to Form1's textbox.

这篇关于从工作区中的另一个类访问 TextBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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