【问题标题】:Accessing Controls Globaly Through A Variable通过变量全局访问控件
【发布时间】:2013-02-17 01:37:54
【问题描述】:

我有两个表单,都带有一个文本框,当输入一个字符串时,富文本框会显示它。我希望能够创建一个类或一些引用,在其中我可以定义一个变量'text'并将其设置为等于输入'textBox1.Text'。当用户在文本框中输入任何内容时,我想将其存储为变量,并将其显示在另一个屏幕上。如果我能做到这一点,你能告诉我,它真的很令人沮丧!

【问题讨论】:

    标签: c#


    【解决方案1】:

    听起来像Passing data between two instantiated WinForms in C#

    但在你的情况下,只需创建一个static class 让说

    public class static Setter
    {
       //Properties
       public static string set1{ get; set; }
       public static string set2 { get; set; }
    }
    

    那你就可以用like了

    string test = "test";
    Setter.set1 = test;
    

    【讨论】:

      猜你喜欢
      • 2017-01-17
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多