private void button1_Click(object sender, EventArgs e) { more hm = new more(); foreach (Control ctr in hm.panel1.Controls) { //判断该控件是不是CheckBox if (ctr is CheckBox) { //将ctr转换成CheckBox并赋值给ck CheckBox ck = ctr as CheckBox; if (this.richTextBox1.Text.IndexOf(ck.Text) > -1) { ck.Checked = true; } } } if (hm.ShowDialog() == DialogResult.OK) { this.richTextBox1.Text = hm.other_symptom; } }
Typically when the (more modern of the) systems I work on are implementing this data layer pattern, such as some Reader, they will take a db context via constructor parameter (dependency injection) and keep it for the life of the class, rather than each method making their own context in a using
public Player(AnchorStyles playerCardsAnchor, more parameters for properties)