bool collect(out QDBDog.Config config) { var data = new Dictionary <string, string>(); foreach (var control in tableLayoutPanel1.Controls) { var ac = control as TextBox; if (ac != null && ac.Tag != null) { data[ac.Tag.ToString()] = ac.Text; } } foreach (var control in panel1.Controls) { var ac = control as RadioButton; if (ac != null && ac.Tag != null) { if (ac.Checked) { data[ac.Tag.ToString()] = ac.Tag.ToString(); } } } data["Name"] = tbName.Text; data["ExpireValue"] = numExpire.Value.ToString("0"); config = data.ToArray().FromNameValuePairs <QDBDog.Config>(); return(true); }
void render(QDBDog.Config config) { var data = config.ToDict(); foreach (var control in tableLayoutPanel1.Controls) { var ac = control as TextBox; if (ac != null && ac.Tag != null) { var a = data.FirstOrDefault(r => r.Key.Equals(ac.Tag.ToString(), StringComparison.OrdinalIgnoreCase)); ac.Text = a.Value; } } foreach (var control in panel1.Controls) { var ac = control as RadioButton; if (ac != null && ac.Tag != null) { var a = data.FirstOrDefault(r => r.Key.Equals(panel1.Tag.ToString(), StringComparison.OrdinalIgnoreCase)); ac.Checked = a.Value == ac.Tag.ToString(); } } tbName.Text = config.Name; numExpire.Value = config.ExpireValue; }