1,创建一个父窗口Form1,添加一个button(为了弹出子窗口) 
2,创建一个子窗口Form2一个Combobox控件 ,一个button按钮(保存参数使用)
3,初始化显示form1,点击button弹出Form2,选择combobox中的数值,值有:0,1,2,3,4 ...,现在任意
   选择其中的一个假定选择了列表中的3,点击button按钮保存并且button按钮变位禁用,再次打开Form2之后combobox中的 值仍旧为3,
   同时Form2中的button仍旧为禁用状态。希望能给出一些详细的代码!谢谢!

解决方案 »

  1.   

    要用到序列化了。用一个XML文件保存这些数据,再次打开的时候,读出这些数据并显示。
      

  2.   

    再次打开Form2让from2 隐藏 不关闭 
     下次打开 显示 就OK 了
      

  3.   

    用txt文件保存也行啊,你不保存下来,那你退出这个程序了,这些数据就没了,所以说,还是要保存下来啊,这是我个人的看法。
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    namespace TestDlgForm1
    {
        public partial class Form2 : Form
        {
            private Form1 pParentWin = null;      
            public Form2(Form1 WinMain)
            {
                InitializeComponent();
              //  m_Form1 = p_Form;
                pParentWin = WinMain;
              
           
            }        private void Form2_Load(object sender, EventArgs e)
            {
               
            }        private void button1_Click(object sender, EventArgs e)
            {
                
            }
        }
    }
    以上是部分代码,是窗口交换数据的问题,但是还是没有解决我要说明的问题!
      

  5.   

    public  Static  int 你要保存的变量;
      

  6.   

    1、属性X保存在父窗口Form1中。
    2、把Form1的对象传入子窗口Form2中。
    3、子窗口Form2中操作属性X,把Combox的值保存在属性X中。
    4、同理,建立其他属性,保存子窗口数据不知道这样是否可以实现楼主的意思
      

  7.   

    不知道这样是否是你需要的
    父窗体代码    public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private int index = 0;
            public int Index
            {
                set
                {
                    index = value;
                }
                get
                {
                    return index;
                }
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.Tag = this;
                f2.ShowDialog();
            }
        }
    子窗体代码    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        
            private void button1_Click(object sender, EventArgs e)
            {        }        private void Form2_Load(object sender, EventArgs e)
            {
                Form1 f1 = this.Tag as Form1;
                this.comboBox1.SelectedIndex = f1.Index;
            }        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
            {
                Form1 f1 = this.Tag as Form1;
                f1.Index = this.comboBox1.SelectedIndex;
            }
        }
      

  8.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Windows.Forms;namespace _00
    {
        public partial class Form4 : Form
        {
            String m_strReader = "";
            String FILE_NAME = "FLIE_.txt";
            String Path = System.Environment.CurrentDirectory.ToString();
            public Form4()
            {
                InitializeComponent();
            }        private void Form4_Load(object sender, EventArgs e)
            {
                try
                {
                    StreamReader srFile = new StreamReader(Path + "\\" + FILE_NAME);
                    while (!srFile.EndOfStream)
                    {
                        m_strReader = srFile.ReadLine().ToString().Trim();                }
                    srFile.Close();
                    this.comboBox1.Text = m_strReader;            }
                catch (System.Exception ex)
                {
                    ;
                }
            }        private void OK_button_Click(object sender, EventArgs e)
            {
                StreamWriter sr;
                if (File.Exists(FILE_NAME))
                {
                    File.Delete(FILE_NAME);
                    sr = File.CreateText(FILE_NAME);
                }
                else
                {
                    sr = File.CreateText(FILE_NAME);
                }
                sr.WriteLine(this.comboBox1.Text);
                sr.Close();
                this.OK_button.Enabled = false;
                this.Close();
            }        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (this.comboBox1.Text.Length > 0 && !this.comboBox1.Text.Equals(m_strReader))
                {
                    this.OK_button.Enabled = true;
                }
                else
                {
                    ;
                }
            }    }
    }
    上面是Form2 的代码。 
      

  9.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Windows.Forms;namespace _00
    {
        public partial class Form4 : Form
        {
            String m_strReader = "";
            String FILE_NAME = "FLIE_.txt";
            String Path = System.Environment.CurrentDirectory.ToString();
            public Form4()
            {
                InitializeComponent();
            }        private void Form4_Load(object sender, EventArgs e)
            {
                try
                {
                    StreamReader srFile = new StreamReader(Path + "\\" + FILE_NAME);
                    while (!srFile.EndOfStream)
                    {
                        m_strReader = srFile.ReadLine().ToString().Trim();                }
                    srFile.Close();
                    this.comboBox1.Text = m_strReader;            }
                catch (System.Exception ex)
                {
                    ;
                }
            }        private void OK_button_Click(object sender, EventArgs e)
            {
                StreamWriter sr;
                if (File.Exists(FILE_NAME))
                {
                    File.Delete(FILE_NAME);
                    sr = File.CreateText(FILE_NAME);
                }
                else
                {
                    sr = File.CreateText(FILE_NAME);
                }
                sr.WriteLine(this.comboBox1.Text);
                sr.Close();
                this.OK_button.Enabled = false;
                this.Close();
            }        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (this.comboBox1.Text.Length > 0 && !this.comboBox1.Text.Equals(m_strReader))
                {
                    this.OK_button.Enabled = true;
                }
                else
                {
                    ;
                }
            }    }
    }
    上面是Form2 的代码。 
      

  10.   

    LZ我刚运行了下可以的
    FORM1代码  设置Form1的IsMdiContainer属性true
    namespace _1234
    {
        public partial class Form1 : Form
        {
            public static string ss = null;
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2();
                f2.MdiParent = this;
                f2.Show();
            }
        }
    }
    Form2代码
    namespace _1234
    {    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }        private void Form2_Load(object sender, EventArgs e)
            {
                comboBox1.Items.AddRange(new string[]{"A","B","C","D"});
                comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
                comboBox1.Text = Form1.ss;
            }        private void button1_Click(object sender, EventArgs e)
            {
                Form1.ss = comboBox1.Text.Trim();
                this.Close();
            }
        }
    }
      

  11.   

    虽然结贴了,但是我还是想不通过建立一个txt来完成这个功能,那位那有没有其他的方法?
      

  12.   

    .....ini  和 txt 有区别吗
      

  13.   

    LZ也可以 吧Form2 的 comboBox1的值传给Form1 保存 
    show() 的时候再调用。。