簡單的C#Windows 窗體程式設計,計算圓的周長、面積與體積。
阿新 • • 發佈:2019-01-04
<pre name="code" class="cpp"><pre name="code" class="csharp"><pre name="code" class="csharp">using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace AreaOf_Circle { public partial class Form1 : Form { public Form1() { InitializeComponent();//窗體初始化 } private void label2_Click(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { double r, l, s, v; r = Convert.ToSingle(textBox1.Text);//獲取輸入半徑 l = Math.PI * 2 * r;//計算周長 s = Math.PI * r * r;//計算面積 v = Math.PI * 3.0 / 4.0 * r * r * r;//計算體積 textBox2.Text = Convert.ToString(l);//顯示周長 textBox3.Text = Convert.ToString(s);//顯示面積 textBox4.Text = Convert.ToString(v);//顯示體積 } private void button2_Click(object sender, EventArgs e) { Application.Exit();//退出 } } }