窗本操作类
主窗体信息与子窗体同步
1、主窗体
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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public string DisplayMessage;
private void Form2_Load(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
Text = DisplayMessage;
}
}
}
2、子窗体
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if(frm!=null)
frm.Invoke(new MethodInvoker(delegate { frm.DisplayMessage = DateTime.Now.ToString(); }));
}
public Form2 frm;
private void button1_Click(object sender, EventArgs e)
{
frm = new Form2();
frm.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}