如何使用从usercontrols检索的数据构建xml?

时间:2014-05-13 11:05:30

标签: c# xml winforms user-controls

我正在尝试制作一个可以修改预先存在的xml文件的软件。我有机会将一些值(通过usercontrols)添加到字母表中,然后将这些值发送回xml,保存它。

我已经回调了xml文件,以便我可以加载我需要的字母列表。 无论如何,首先,我需要从usercontrols中检索数据。

以下是包含所有内容的表单中的代码:

public partial class SettingLetterInput : UserControl {

    Dictionary<char, Actions> ListaLettere;

    public SettingLetterInput() {
        InitializeComponent();
    }





    private void SettingLetterInput_Load(object sender, EventArgs e) {

        string path = Path.GetFullPath("Config.xml");
        ListaLettere = Actions.GetFromXML(path);
        listLetterBox1.Items.AddRange(
            ListaLettere.Select(l => (object)l.Key).ToArray());

        foreach (var a in Enum.GetValues(typeof(Actions.acts))) {
            actionsBox.Items.Add(a);
        }

    }





    private void AddActionBtn_Click(object sender, EventArgs e) {
        if (actionsBox.Text != "") {
            Actions.acts act = (Actions.acts)Enum.Parse(typeof(Actions.acts), actionsBox.Text);
            AddRow(act, null);
        } else {
            MessageBox.Show("no action selected");
        }


    }




    public void AddRow(Actions.acts act, object values) {
        ActionRowCtrl arc;

        #region switch per controls
        switch (act) {

            case Actions.acts.addPosition:
                arc = new ActionRow_SizeCtrl(values);
                arc.actNameLbl.Text = this.actionsBox.Text;
                break;

            case Actions.acts.changeColor:
                arc = new ActionRow_ColorCtrl(values);
                arc.actNameLbl.Text = this.actionsBox.Text;
                break;
            case Actions.acts.addCircle:
                arc = new ActionRow_FormCtrl();
                arc.actNameLbl.Text = this.actionsBox.Text;
                break;

            default:
                arc = new ActionRowCtrl();
                break;
        }
        #endregion

        this.panel1.Controls.Add(arc);

        positionRow();
    }




    public void positionRow() {


        int lastTop = -1;
        int lastHeight=0;
        int rowN = 0;
        foreach (ActionRowCtrl c in panel1.Controls) {
            rowN++;
            c.rowLbl.Text = rowN.ToString();
            if (( rowN % 2 ) == 0)
                c.BackColor = Color.White;
            else
                c.BackColor = Color.Bisque;

            c.Top = 0;
            if (lastTop > -1) {
                c.Top = lastTop + lastHeight;
            }
            lastTop = c.Top;
            lastHeight = c.Height;
        }
    }



    public void deleteRow(ActionRowCtrl arc) {
        this.panel1.Controls.Remove(arc);
        arc.Dispose();
        positionRow();
    }

0 个答案:

没有答案