private void listView2_SelectedIndexChanged(object sender, EventArgs e) { if (listView2.SelectedItems.Count == 1) { comboBox1.Enabled = false; Config.Rule r = (Config.Rule)listView2.SelectedItems[0].Tag; textBox2.Text = r.x.ToString(); textBox3.Text = r.y.ToString(); button8.Text = "Apply"; } else { comboBox1.Enabled = true; textBox2.Text = textBox3.Text = ""; button8.Text = "Add"; } }
private void button8_Click(object sender, EventArgs e) { try { if (textBox2.Text == "") { throw new Exception("Input x"); } if (textBox3.Text == "") { throw new Exception("Input y"); } int x = int.Parse(textBox2.Text); x = x / 4 * 4; int y = int.Parse(textBox3.Text); if (listView2.SelectedItems.Count == 1) { Config.Rule r = (Config.Rule)listView2.SelectedItems[0].Tag; r.x = x; r.y = y; reread(); return; } if (comboBox1.SelectedIndex < 0) { throw new Exception("Select letter"); } int letter = conf.letterByImage((Bitmap)comboBox1.Items[comboBox1.SelectedIndex]); conf.rules.Add(new Config.Rule(x, y, letter)); reread(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }