Как сделать так чтобы при выборе checkBox2 при нажатии на кнопку button2 в случае если кнопка button1 не была нажата форма закрывалась. А если кнопка button1 была нажата и из списка listBox был выбран элемент при нажатии на кнопку button2 открывалась новая форма?
| Код | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;
namespace AnimalKingdom { public partial class Main : Form { private int myVar = 0;
public Main() { InitializeComponent(); comboBox1.Enabled = false; groupBox2.Enabled = false; listBox1.Enabled = false; String[] w = { "Australia", "Russia", "China", "Japan", "India", "Nepal" }; listBox1.Items.AddRange(w); }
private void checkBox1_CheckedChanged(object sender, EventArgs e) { }
private void checkBox2_CheckedChanged(object sender, EventArgs e) { }
private void checkBox3_CheckedChanged(object sender, EventArgs e) { button2.Text = "Show"; }
private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked) { MessageBox.Show("Animal Name Selection Section Enabled"); groupBox1.Enabled = false; comboBox1.Enabled = true; groupBox2.Enabled = true; String[] s = { "Обезьяна", "Медведи", "Бык", "Кот и пчела", "Кот", "Собака", "Ослик", "Свинья", "Белка" }; comboBox1.Items.AddRange(s);
comboBox1.SelectedIndex = comboBox1.Items.IndexOf(comboBox1.Text); }
if (checkBox2.Checked) { MessageBox.Show("Country Name Selection Section Enabled"); listBox1.Enabled = true; listBox1.Items.Clear(); String[] w = { "Australia", "Russia", "China", "Japan", "India", "Nepal" }; listBox1.Items.AddRange(w);
if (button2.Text == "Show") { button2.PerformClick(); } }
if (checkBox3.Checked) { button2.Text = "Show"; MessageBox.Show("All Animals"); groupBox1.Enabled = false; }
if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked) { MessageBox.Show("All Animals"); groupBox1.Enabled = false; } }
private void button2_Click(object sender, EventArgs e) { if (!checkBox1.Checked && !checkBox2.Checked && !checkBox3.Checked) { this.Close(); }
if (checkBox1.Checked) { this.Close(); }
if (checkBox2.Checked) { if (myVar % 2 == 0) { ImageForm NewForm = new ImageForm(); NewForm.Show(); } else { this.Close(); } myVar = myVar + 1; }
if (checkBox3.Checked) { if (myVar % 2 == 0) { ImageForm NewForm = new ImageForm(); NewForm.Show(); } else { this.Close(); } myVar = myVar + 1; } }
private void comboBox1_ChangeText(object sender, EventArgs e) { if (comboBox1.SelectedIndex >= 0) { button2.Text = "Show"; } else { button2.Text = "Exit"; } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedIndex >= 0) { button2.Text = "Show"; } else { button2.Text = "Exit"; } } } }
|
|