class 操作类{ Form form; public 操作类(Form f){ this.form=f; } public void Write(){ (form as Form1).ShowText("123"); //或者(form as Form1).TB.Text="123"; } } -------- Form1中 给Form1添加一个方法~~ public void ShowText(string str){ this.TextBox1.Text=str; } 或者一个属性 public TextBox TB{ get{ return this.TextBox1; } } -------------------------- 操作类 c=new 操作类(this);
简单的委托和事件参考 public partial class Form1 : Form { class test { public delegate void writeText(string strText); public event writeText onWrite; public void DoWrite() { if (this.onWrite != null) { this.onWrite("jinjazz"); } } } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { test t = new test(); t.onWrite += new test.writeText(t_onWrite); t.DoWrite(); } void t_onWrite(string strText) { this.textBox1.Text = strText; }
Form form;
public 操作类(Form f){
this.form=f;
}
public void Write(){
(form as Form1).ShowText("123");
//或者(form as Form1).TB.Text="123";
}
}
--------
Form1中
给Form1添加一个方法~~
public void ShowText(string str){
this.TextBox1.Text=str;
}
或者一个属性
public TextBox TB{
get{
return this.TextBox1;
}
}
--------------------------
操作类 c=new 操作类(this);
{
class test
{
public delegate void writeText(string strText); public event writeText onWrite; public void DoWrite()
{
if (this.onWrite != null)
{
this.onWrite("jinjazz");
}
}
} public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
test t = new test();
t.onWrite += new test.writeText(t_onWrite);
t.DoWrite();
} void t_onWrite(string strText)
{
this.textBox1.Text = strText;
}
}