How to edit and save settings in a Form?

后端 未结 2 1291
日久生厌
日久生厌 2020-12-07 03:22

I have a form that contains several text boxes, radio buttons, checkboxes etc. Right now I am saving their values respectively by declaring each one and saving to the progra

2条回答
  •  半阙折子戏
    2020-12-07 03:41

    One way of doing this would be to loop through all the controls and in each iteration check the type of the current control and save accordingly. However I'm not too sure what you can do about the RadioButtons/CheckBoxes.

    foreach (var c in this.Controls)
    {
        var _type = c.GetType();
        if (_type == typeof(TextBox))
        {
            // Cast it to a textbox and save it's text property
        }
        elseif (_type == typeof(ListBox)
        {
            // Cast it to a listbox and save it's items property
        }
        // So on...
     }
    

提交回复
热议问题