예제 #1
0
    public static void SetValue(Form form)
    {
        Control ctrl = null;

        while ((ctrl = form.GetNextControl(ctrl, true)) != null)
        {
            SettingLoader.SetValue(ctrl);
        }
    }
예제 #2
0
    public static void SetValue(Control ctrl)
    {
        string Name = ctrl.FindForm().Name + '-' + ctrl.Name;

        if (ctrl.Tag != null && ctrl.Tag.ToString().Trim().Length > 0)
        {
            switch (ctrl.GetType().Name)
            {
            case "TextBox":
                SettingLoader.SetValue((string)ctrl.Tag, ctrl.Text);
                break;

            case "CheckBox":
                CheckBox check = (CheckBox)ctrl;
                SettingLoader.SetValue((string)ctrl.Tag, check.Checked);
                break;

            case "RadioButton":
                RadioButton radio = (RadioButton)ctrl;
                SettingLoader.SetValue((string)ctrl.Tag, radio.Checked);
                break;

            case "NumericUpDown":
                NumericUpDown numeric = (NumericUpDown)ctrl;
                SettingLoader.SetValue((string)ctrl.Tag, numeric.Value.ToString());
                break;

            case "TabControl":
                TabControl tab = (TabControl)ctrl;
                SettingLoader.SetValue((string)ctrl.Tag, tab.SelectedIndex.ToString());
                break;

            case "ComboBox":
                ComboBox combo = (ComboBox)ctrl;
                try
                {
                    string      fileName = null;
                    XmlDocument doc      = null;
                    XmlNode     element  = GetCtrlNode(ctrl, ref fileName, ref doc);
                    element.RemoveAll();
                    foreach (string item in combo.Items)
                    {
                        XmlNode node = doc.CreateNode(XmlNodeType.Element, "Item", "");
                        node.InnerText = item;
                        element.AppendChild(node);
                    }
                    doc.Save(fileName);
                }
                catch (XmlException)
                {
                }
                SettingLoader.SetValue(Name, combo.Text);
                break;

            case "ListView":
                ListView list = (ListView)ctrl;
                try
                {
                    string      fileName = null;
                    XmlDocument doc      = null;
                    XmlNode     element  = GetCtrlNode(ctrl, ref fileName, ref doc);
                    element.RemoveAll();
                    foreach (ListViewItem viewItem in list.Items)
                    {
                        XmlNode node = doc.CreateNode(XmlNodeType.Element, "Item", "");
                        if (list.CheckBoxes == true)
                        {
                            XmlAttribute attribute = doc.CreateAttribute("Checked");
                            attribute.Value = viewItem.Checked.ToString();
                            node.Attributes.Append(attribute);
                        }
                        string InnerText = "";
                        foreach (ListViewItem.ListViewSubItem subItem in viewItem.SubItems)
                        {
                            InnerText += subItem.Text + '\t';
                        }
                        node.InnerText = InnerText.TrimEnd('\t');
                        element.AppendChild(node);
                    }
                    doc.Save(fileName);
                }
                catch (XmlException)
                {
                }
                break;
            }
        }
    }