private void checkBox1_CheckStateChanged(object sender, EventArgs e) { this.button1.Visible = this.checkBox1.Checked; increment(); } private void button1_Click(object sender, EventArgs e) { this.checkBox1.Visible = !this.checkBox1.Visible; increment(); } private void checkBox2_CheckStateChanged(object sender, EventArgs e) { this.button2.Visible = this.checkBox2.Checked; increment(); } private void button2_Click(object sender, EventArgs e) { this.checkBox2.Visible = !this.checkBox2.Visible; increment(); } private int antal = 0; // Medlemsvariabel i klassen private void increment() { ++antal; this.label1.Text = "Antal: " + antal; }
private void button3_Click(object sender, EventArgs e) { SqlCeConnection con = new SqlCeConnection(); SqlCeCommand com = new SqlCeCommand(); try { con.ConnectionString = "Data Source=\\My Documents\\Planeter.sdf"; con.Open(); com.Connection = con; com.CommandText = "insert into planeter " + "(nummer, namn, befolkning) " + "values (" + this.textBox1.Text + ", '" + this.textBox2.Text + "', " + this.textBox3.Text + ")"; com.ExecuteNonQuery(); MessageBox.Show("Sparat planeten."); } catch (SqlCeException ex) { MessageBox.Show("Misslyckades med att " + "köra insert-frågan: " + ex.Errors[0].Message); } catch (Exception ex) { MessageBox.Show("Misslyckades med att " + "köra insert-frågan: " + ex.ToString()); } finally { con.Close(); } }