消息窗口,子窗口和父窗口同步问题

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;
using System.Collections;
 
namespace ShowWindow
{
    public partial class Message : Form
    {
        private ArrayList listMsg = new ArrayList();
        private int msgListIndex = 0;
        public Message()
        {
            listMsg.Add("1Message");
            listMsg.Add("2Message");
            listMsg.Add("3Message");
            listMsg.Add("4Message");
            listMsg.Add("5Message");
            listMsg.Add("6Message");
            listMsg.Add("7Message");
            listMsg.Add("8Message");
            listMsg.Add("9Message");
            listMsg.Add("10Message");
            listMsg.Add("11Message");
            listMsg.Add("12Message");
            listMsg.Add("13Message");
 
 
            InitializeComponent();
            this.richTextBox1.Text = this.listMsg[msgListIndex].ToString();
            this.label1.Text = string.Format("{0}/{1}", msgListIndex + 1, listMsg.Count);
            this.msgListIndex++;
 
 
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            if (this.msgListIndex==-1)
            {
                this.button1.Enabled = true;
                this.msgListIndex += 2;
            }
            this.richTextBox1.Text = this.listMsg[msgListIndex].ToString();
            this.label1.Text = string.Format("{0}/{1}", msgListIndex + 1, listMsg.Count);
            this.msgListIndex++;
            if (msgListIndex==listMsg.Count)
            {
                this.button3.Enabled = false;
            }
        }
        frmMain parent = null;
        public Message(Form parent):this()
        {
            this.parent = parent as frmMain;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Owner.Activate();//Focus
 
        }
 
        void Message_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Hide();
           this.Owner.Activate();//Focus
        }
 
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.msgListIndex == listMsg.Count)
            {
                this.button3.Enabled = true;
                this.msgListIndex -= 2;
            }
            this.richTextBox1.Text = listMsg[msgListIndex].ToString();
            this.label1.Text = string.Format("{0}/{1}", msgListIndex + 1, listMsg.Count);
 
            this.msgListIndex--;
            if (msgListIndex == -1)
            {
                button1.Enabled = false;
            }
                    
 
 
        }
    }
}




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;
using System.Configuration;
 
 
namespace ShowWindow
{
    public partial class frmMain : Form
    {
        public frmMain()  
        {
            InitializeComponent();
        }
 
        private void btnShow_Click(object sender, EventArgs e)
        {
            String strMsg = ConfigurationManager.AppSettings["show"].ToString();
            MessageBox.Show(strMsg);
 
        }
 
        private void btnShowName_Click(object sender, EventArgs e)
        {
            string strName = Properties.Settings.Default.strSearchWebsite.ToString();
            MessageBox.Show(strName);
        }
 
        private void frmMain_Load(object sender, EventArgs e)
        {
 
            //int result = this.FindSum(5);
            //MessageBox.Show(result.ToString());//输出5
            //
        //    int key = 0;
         //   int result;
 
         //   while (true)
         //   {
             ////   result = this.RegFindValue(4) + this.RegFindValue(3);//递归算法的调用
             ////   MessageBox.Show(result.ToString());//连续输出五次5
             //   key++;
             //   if (key == 5)
             //       break;
 
           // }
 
 
            //MessageBox.Show(result.ToString());
            //循环算法的调用
            int value = LoopFindValue(6);
            MessageBox.Show(value.ToString());
 
 
        }
 
        //递归算法的实现
        private int RegFindValue(int m)
        {
            if (m == 1 || m == 2)
                return 1;
            else
                return RegFindValue(m - 1) + RegFindValue(m - 2);
        }
 
 
        //循环算法的实现
        private int LoopFindValue(int n)
        {
            if (n <= 1)
                return 0;
 
 
            int result = 0;
            int firstnum = 0, secondnum = 0;
            for (int i = 1; i <= n; i++)
            {
                if (i == 1 || i == 2)
                    result = firstnum = secondnum = 1;
                else
                {
                    result = firstnum + secondnum;
                    firstnum = secondnum;
                    secondnum = result;
 
 
                }
 
            }
            return result;
        }
        Message msg;
 
        private void button2_Click(object sender, EventArgs e)
        {
            
            if (msg == null)
            {
 
                msg = new Message();
               msg.Owner =(frmMain)System.Windows.Forms.Form.FromHandle(this.Handle);
            //    msg.Owner = this;
               msg.Show();
                            
 
            }
            else
            {
                if (!msg.Visible)
                {
                    if (msg != null)
                    {
 
                        msg.Show();
                        //msg.Visible = false;
 
                    }
 
 
 
                }
                else
                {
                   
                  //  msg.Activate();
                }
            }
            
 
	
 
            }
    }
}
        
      
 
 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2013-04-19 07:32  Predator  阅读(239)  评论(0编辑  收藏  举报