如何将消息从另一个类写入WinFrm? [英] How to write message from another class to WinFrm?
本文介绍了如何将消息从另一个类写入WinFrm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我定义了一个类TestClient。
I define a class TestClient.
在TestClient中,我想在WinFrm TextBox上写消息。
In TestClient, I want to write message on WinFrm TextBox.
有关如何操作的任何建议吗?
Any suggestion on how to do it?
谢谢,
推荐答案
public class TestClient
{
public delegate void myEventHandler(string message);
// Declare the event.
public event myEventHandler myEvent;
public void RaiseMyEvent()
{
if (myEvent != null)
{
myEvent("Hello");
}
}
}
public partial class Form1 : Form
{
TestClient objTestClient = new TestClient();
public Form1()
{
InitializeComponent();
objTestClient.myEvent += ObjTestClient_myEvent;
}
private void ObjTestClient_myEvent(string message)
{
MessageBox.Show(message);
}
private void button_Click(object sender, EventArgs e)
{
objTestClient.RaiseMyEvent();
}
}
这篇关于如何将消息从另一个类写入WinFrm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文