日期:2014-05-17  浏览次数:21095 次

winform中 一个普通的类如何给Textbox赋值
RT
我在网上看到了很多窗体传值的方式,但是普通的类如何控制就不知道了。

我在 form中new了一个对象,让后把form传进去,但是也不能修改Textbox上的值啊。

------解决方案--------------------
没甚理解 楼主的意思 看下:
 class Class1
    {
        public static void changeTextValue(System.Windows.Forms.TextBox tb,string v) {
            tb.Text = v;
        }
    }
   private void button1_Click(object sender, EventArgs e)
        {

            Class1.changeTextValue(textBox1, "test");//textBox1为from中textbox 的id
}
------解决方案--------------------
button1就是 from 中的按钮啊
textBox1为form 中的文本框

楼主可否举个例子,具体的功能
------解决方案--------------------
一个普通类给txtBox赋值
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            A a = new A();
            txtBox1.Text = a.TextString;
        }
    }

    class A
    {
        public string TextString
        {
            get { return "Yes"; }
        }
    }

new了一个对象,让后把form传进去
 public partial class Form1 : Form
    {
        public Form1()