你们说的是没错,但是文本框没有显示出来我要结果呀。上代码using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;namespace REDF.Utils.MOXA { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { M2K_getUdpMessage(); } public static void M2K_getUdpMessage() { string szShowData = "hello"; Form2 frm = new Form2(); frm.AddMsg(szShowData); } public void AddMsg(string msg) { textBox1.Focus(); textBox1.Text = msg; //Console.WriteLine("hello"); this.Refresh(); } } }
if (test == null)
{
return;
}
test.Invoke(new Form1(),null);
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace REDF.Utils.MOXA
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
M2K_getUdpMessage();
} public static void M2K_getUdpMessage()
{
string szShowData = "hello";
Form2 frm = new Form2();
frm.AddMsg(szShowData);
} public void AddMsg(string msg)
{
textBox1.Focus();
textBox1.Text = msg;
//Console.WriteLine("hello");
this.Refresh();
}
}
}
你看没看我想要的结果?你说的对,那样调用是没问题,但是这样也不能把想要的结果在当前页面的TextBox显示呀?
应该用实例方法调用静态方法返回值,并在此实例方法中给form中的控件赋值。
private void button1_Click(object sender, EventArgs e)
{
string msg= M2K_getUdpMessage();
AddMsg(msg);
} public static string M2K_getUdpMessage()
{
string szShowData = "hello";
} public void AddMsg(string msg)
{
textBox1.Focus();
textBox1.Text = msg;
//Console.WriteLine("hello");
this.Refresh();
}