lundi 21 septembre 2015

C# Getting data from "Control" type to store assortment of other Controls (CheckBox/TextBox/NumericUpDown etc)

I have a type that contains a few strings and a generic Control, My problem is that I don't know how to access the data that is stored inside the control.

Basically My program loops through some "custom types" which have _control "Children" which are then assigned to New CheckBox or other form controls.

    private Control _control { get; set; }
    public void set_control(Control control) { this._control = control; } 

elsewhere
x.set_control(new CheckBox { Dock = DockStyle.Fill, AutoSize = false, Text = x.name(), Checked = Convert.ToBoolean(x.data()) }); x.control().Click += delegate { refresh_data(x); };

psudo Code

private void refresh_data(embedded_setting setting) { if(setting.control().GetType() == typeof(CheckBox)) { setting.set_data(setting.control()); } }
I need to set_data to control.checked.tostring. But im not sure how to use the control type as if its a checkbox type.

I'm hoping it can be carried over to be used with TextBox.Text and NumericUpDown.Value as well.

Hopefully the question makes sense, let me know if it doesn't.




Aucun commentaire:

Enregistrer un commentaire