private void btn_click(object sender, EventArgs e) { double A, B, C; A = Convert.ToDouble(a.Text); B = Convert.ToDouble(b.Text); C = Convert.ToDouble(c.Text); double Ans1, Ans2, va; va = Math.Sqrt(B * B - 4 * A * C); Ans1 = (-B + va) / (2 * A); Ans2 = (-B - va) / (2 * A); Ans.Text = " Ans1=" + Ans1.ToString("0.0#") + " Ans2=" + Ans2.ToString("0.0#"); }
}//private void AdjustDataGridViewSizing() private void button5_Click(object sender, EventArgs e)// [Truth table] { // Create an unbound DataGridView by declaring a column count. dataGridView1.ColumnCount = 5; dataGridView1.ColumnHeadersVisible = true; AdjustDataGridViewSizing(); // Set the column header style. DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle(); columnHeaderStyle.BackColor = Color.Aqua; columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold); dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle; // Set the column header names. dataGridView1.Columns[0].Name = "A"; dataGridView1.Columns[1].Name = "B"; dataGridView1.Columns[2].Name = "A && B"; dataGridView1.Columns[3].Name = "A || B"; dataGridView1.Columns[4].Name = "!A"; // Populate the rows. bool A, B, Ans1, Ans2, Ans3; // A = true; B = true; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row1 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; A = true; B = false; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row2 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; A = false; B = true; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row3 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; A = false; B = false; Ans1 = A && B; Ans2 = A || B; Ans3 = !A; string[] row4 = new string[] { A.ToString(), B.ToString(), Ans1.ToString(), Ans2.ToString(), Ans3.ToString() }; // object[] rows = new object[] { row1, row2, row3, row4 }; foreach (string[] rowArray in rows) { dataGridView1.Rows.Add(rowArray); } // // Set the row header style. DataGridViewCellStyle rowHeaderStyle = new DataGridViewCellStyle(); rowHeaderStyle.BackColor = Color.Lime; rowHeaderStyle.Font = new Font("Verdana", 7, FontStyle.Italic); dataGridView1.RowHeadersDefaultCellStyle = rowHeaderStyle; // dataGridView1.Rows[0].HeaderCell.Value = "a"; dataGridView1.Rows[1].HeaderCell.Value = "b"; dataGridView1.Rows[2].HeaderCell.Value = "c"; dataGridView1.Rows[3].HeaderCell.Value = "d"; // dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 7); }//private void button5_Click(object sender, EventArgs e)