日期:2014-05-17  浏览次数:20839 次

高分悬赏求大神们帮忙
求大神帮忙。要解决的问题如下:
有两个窗体,主窗体Form1,子窗体Form2。Form1中有个TextBox1,Button1,子窗体Form2中有Button2,
假如我点击Button1,弹出Form2,然后我点击Button2后,程序会读取Bin里面的一个log.text文件内容,我想然后将读取的内容显示在Form1中的TextBox1中。也就是跨窗体显示。现在假如读取内容在Form2中显示,我可以做到,但怎么在Form1上显示呢?这个是截图就是这样的效果
textbox

------解决方案--------------------
参考这个http://blog.csdn.net/bdstjk/article/details/7005798
------解决方案--------------------

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowLog += new EventHandler<LogEventArgs>(f2_ShowLog);
            f2.Show();
        }
        void f2_ShowLog(object sender, LogEventArgs e)
        {
            textBox1.Text = e.Text;
        }
    }
}


namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OnShowLog(new LogEventArgs("log log log log log"));
        }
        private void OnShowLog(LogEventArgs e)
        {
            if (ShowLog != null) ShowLog(this, e);
        }
        public event EventHandler<LogEventArgs> ShowLog;
    }
    public class LogEventArgs