如何在类中 获得窗体 Form1中textBox1的值?? 如何在类中 获得窗体 Form1中textBox1的值?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以让窗体管给它一个委托:class MyClass{ private Func<string> getTextBoxValue; public MyClass(Func<string> func) { getTextBoxValue = func; } public void foo() { string s = getTextBoxValue(); ... }}窗体中:MyClass obj = new MyClass(() => textBox1.Text);obj.foo(); 你也可以在窗体中定义一个静态方法 获取textbox的值 class中调用静态方法还可以把textbox改成静态的 class中直接调用方法很多很多的说 Func 是个代理我知道 可是我用的时候没找到命名空间 自己写了个委托,可以了!呵呵 C#服务方式进程间通讯, 矩阵填数? C#中类库连接ACCESS的代码?急!! 关于 Application? C#Web应用程序基础 高级treeview问题!急!!! 请教高手,C#数据库中导出的Image如何存到excel中?(不读取硬盘,直接内存操作) 用C#如何模拟打开网页和用户输入 请问版主,怎么发了贴子在问题列表中看不见?? 无法将 lambda 表达式 转换为类型“System.Delegate”,因为它不是委托类型。 asp.net里的gridviw更新草组 怎样显示剩余房间数
class MyClass
{
private Func<string> getTextBoxValue;
public MyClass(Func<string> func)
{
getTextBoxValue = func;
}
public void foo()
{
string s = getTextBoxValue();
...
}
}窗体中:
MyClass obj = new MyClass(() => textBox1.Text);
obj.foo();
还可以把textbox改成静态的 class中直接调用
方法很多很多的说