c# 窗体textbox.text传递给类

来源:百度知道 编辑:UC知道 时间:2024/06/17 20:26:23

下面的错了 参考这个:
class Class1
{

private string strValue = string.Empty;

public string str
{
get{ return strValue;}
set { strValue = value; }
}
}

Form:
Class1 s = new Class1();
s.str = this.textbox1.text.trim();

]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]

方法很多的,这里讲一个,希望对你有用,饿着肚子写的呵呵
举例子:
一个类 名为: classTest
一个文本框 (主窗体中)名为: txtTrans
下面构造属性传植:
1.
public class classTest
{
private string strValue = string.empty;//接收textbox的值
public string MyValue//声明一个属性,带有get set 方法
{
get{return strValue;}
set{strValue =value;}
}

}
2.在窗体的textbox传植.
classTest test = new classTest();

test.Myvalue = this.txtTrans.text.trim();//付值

3. 这样你就实现了传植.在classTest里可以 直接用
strValue 的值了 ,因为他被更改了!!