C# 界面间数据传递
来源:互联网 发布:推荐算法 数据集 编辑:程序博客网 时间:2024/04/28 13:50
两界面的数据传递是通过定义 static string来确定的。
一端:Form1
public static string str1; // 在Form1 中定义
另一端:Form2
label = Form1.str1; //在Form2 中实现,数据的传递
Form1
:
using System.Threading;
namespace shuju
{
public partial class Form1 : Form
{
Thread thread;
public delegate void hua(); // 定义委托
public static string str1;
public Form1()
{
InitializeComponent();
Form2 frm = new Form2(); //打开另一界面
frm.Show();
thread = new Thread(new ThreadStart(thread_str)); // 创建线程
thread.Start();
}
public void thread_str()
{
while(true)
{
bbbb();
}
}
public void bbbb()
{
try
{
if (label1.InvokeRequired)
{
hua ff = new hua(bbbb);
this.Invoke(ff);
}
else
{
label1.Text = Form2.str2;
}
}
catch (Exception e)
{
thread.Abort();
MessageBox.Show(e.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
str1 = textBox1.Text;
textBox1.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
//label1.Text = Form2.str2;
}
}
}
Form2:
using System.Threading;
namespace shuju
{
public partial class Form2 : Form
{
public delegate void bian(); //定义委托
Thread thread;
public static string str2;
public Form2()
{
InitializeComponent();
thread = new Thread(new ThreadStart(threading)); //线程
thread.Start();
}
public void threading()
{
while (true)
{
Setting();
}
}
public void Setting() // 刷新 label
{
try
{
if (this.label1.InvokeRequired)
{
bian fc = new bian(Setting);
this.Invoke(fc);
}
else
{
label1.Text = Form1.str1;
}
}
catch(Exception e)
{
thread.Abort();
MessageBox.Show(e.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = Form1.str1;
}
private void button2_Click(object sender, EventArgs e)
{
str2 = textBox1.Text;
}
}
}
- C# 界面间数据传递
- C#两个界面之间数据传递的问题
- 多界面间传递数据的模型
- Matlab GUI 界面间数据的传递
- C# 窗口间传递数据
- C#窗体间传递数据
- C# 窗体间传递数据
- 跳转界面传递数据
- QT界面数据传递
- ios界面之间传递数据
- C#窗体间传递复杂数据
- c#窗体间传递复杂数据
- C#不同窗体间通信,数据传递
- C#不同窗体间数据传递
- javaFX——不同界面间的数据传递
- ReactNative之刷新机制和界面间的数据传递
- iPhone delegate 两界面传递数据(转)
- MATLAB GUI界面之间的数据传递
- OFBiz 的MVC框架
- try btrace before I proceed to work on dacapo.
- {!!}Windows 2003 上配置 VPN + NAT以及VPN的端口映射详解
- BTrace使用简介
- java中求100到1000的质数和
- C# 界面间数据传递
- Redmine、Apache、Git集成遇到的重重困难
- 解决java java.io.FileNotFoundException: http:\localhost:8080 (文件名、目录名或卷)问题
- 高性能mysql之统计表
- 关于FND_PROFILE与FND_GLOBLE
- 删除指针
- 为kindeditor添加在线播放视频功能(基于原有flash上传,mp4,flv,flash)
- Java Test network connection and set TimeOut time length
- Android SurfaceView 详解(二)