Exemplo n.º 1
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.InitialDirectory = Application.StartupPath + "\\Configs";
            dialog.Title            = "选择文件";
            dialog.Filter           = "配置文件|*.ini";

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                txtPath.Text = dialog.FileName;

                OperateIniFile operateIniFile = new OperateIniFile();
                operateIniFile.LoadIniFile(dialog.FileName);

                foreach (var sections in operateIniFile.Items)
                {
                    string section = sections.Key;
                    Dictionary <string, string> values = sections.Value;

                    foreach (var item in values)
                    {
                        lstKeys.Items.Add(item.Key);
                        string[] vals = item.Value.Split(',');
                        lstValues.Items.Add(vals[1]);
                    }
                }
            }
        }