C#类中访问窗体中的TEXTBOX。
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public delegate string ProcessDelegate(string s1, string s2);
public delegate void settext(string str2);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void Writetext(string str)
{
if (this.textBox1.InvokeRequired)
{
this.textBox1.BeginInvoke(new settext(Writetext), str);
return;
}
textBox1.AppendText(str + Environment.NewLine);
}
private void button1_Click(object sender, EventArgs e)
{
/* 调用方法 */
Test t = new Test();
string r1 = t.Process("Text1", "Text2", new ProcessDelegate(t.Process1));
string r2 = t.Process("Text1", "Text2", new ProcessDelegate(t.Process2));
string r3 = t.Process("Text1", "Text2", new ProcessDelegate(t.Process3));
textBox1.Text = r1 + "|" + r2 + "|" + r3;
}
}
public class Test
{
public string Process(string s1, string s2, ProcessDelegate process)
{
return process(s1, s2);
}
public string Process1(string s1, string s2)
{
return s1 + s2;
}
public string Process2(string s1, string s2)
{
return s1 + Environment.NewLine + s2;
}
public string Process3(string s1, string s2)
{
return s2 + s1;
}
public string process4(string s2,string s3)
{
return s2 + s3 + "类访问窗体";
}
}
怎样在test类的process4函数中给TEXTBOX3.TEXT赋值 。