C#类中访问窗体中的TEXTBOX。

orienteer orienteer 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
代码如下:
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赋值 。
...全文
评论 1
收藏 已收藏
分享
返回顶部
orienteer
C# 111,129 成员 642,538 内容