在Class 中添加一个成员 class TEST { public System.Windows.Forms.ListBox lbox public void WriteToForm(string msg) { lbox.Items.Add(msg); } }比如在Form1.cs中调用,在Form1中有一个ListBox控件实例 listBox1 TEST test = new TEST(); test.lbox = this.listBox1; test.WriteToForm("从自定义类中向窗体添加文字");
class TEST
{
public System.Windows.Forms.ListBox lbox
public void WriteToForm(string msg)
{
lbox.Items.Add(msg);
}
}比如在Form1.cs中调用,在Form1中有一个ListBox控件实例 listBox1
TEST test = new TEST();
test.lbox = this.listBox1;
test.WriteToForm("从自定义类中向窗体添加文字");
set{
_message = value;
//将_message的值加入到ListBox中;
...
}
在你的class中frm.listbox.Items.Add(msg);