最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#實(shí)現(xiàn)計(jì)算器功能(winform版)

 更新時(shí)間:2022年01月28日 15:01:47   作者:Dust_SongYunfei  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)winform版的計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C#實(shí)現(xiàn)計(jì)算器功能的具體代碼,供大家參考,具體內(nèi)容如下

代碼:

Random rad = new Random(); // 實(shí)例化隨機(jī)對象
? ? ? ? private void Form1_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Left = Screen.PrimaryScreen.WorkingArea.Width / 2 - this.Width / 2;
? ? ? ? ? ? this.Top = Screen.PrimaryScreen.WorkingArea.Height / 2 - this.Height / 2;
? ? ? ? ? ? this.Text = "計(jì)算器";
? ? ? ? ? ? textBox1.ReadOnly =true;// 文本框無法輸入字符
? ? ? ? ? ? foreach (Control ctl in this.Controls)
? ? ? ? ? ? { ? // 獲取所有按鈕 ?改變背景顏色和數(shù)字和符號(hào)顏色
? ? ? ? ? ? ? ? if (ctl is Button)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Button btn = ctl as Button;
? ? ? ? ? ? ? ? ? ? btn.BackColor = Color.FromArgb(rad.Next(256),rad.Next(256),rad.Next(256),rad.Next(256));
? ? ? ? ? ? ? ? ? ? btn.ForeColor = Color.FromArgb(rad.Next(256), rad.Next(256), rad.Next(256));
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? private void 關(guān)閉ToolStripMenuItem_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Close();// 關(guān)閉窗體
? ? ? ? }
? ? ? ? char fuhao;// 接收符號(hào)
? ? ? ? double temp, num; // temp第一個(gè)值,num為第二個(gè)值
? ? ? ?// 1
? ? ? ? private void button1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "1";
? ? ? ? }
? ? ? ? // 2
? ? ? ? private void button2_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "2";
? ? ? ? }
? ? ? ? // 3
? ? ? ? private void button3_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "3";
? ? ? ? }
? ? ? ? // 4
? ? ? ? private void button5_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "4";
? ? ? ? }
? ? ? ? // 5
? ? ? ? private void button6_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "5";
? ? ? ? }
? ? ? ? // 6
? ? ? ? private void button7_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "6";
? ? ? ? }
? ? ? ? // 7
? ? ? ? private void button9_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "7";
? ? ? ? }
? ? ? ? // 8
? ? ? ? private void button10_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "8";
? ? ? ? }
? ? ? ? // 9
? ? ? ? private void button11_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "9";
? ? ? ? }
? ? ? ? // 0
? ? ? ? private void button15_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += "0";
? ? ? ? }
? ? ? ? //點(diǎn)
? ? ? ? private void button16_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text += ".";
? ? ? ? }

? ? ? ? // +
? ? ? ? private void button4_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? num = double.Parse(textBox1.Text);
? ? ? ? ? ? fuhao = '+';
? ? ? ? ? ? textBox1.Text += "+";
? ? ? ? ? ? //textBox1.Text = null;
? ? ? ? }
? ? ? ? // -
? ? ? ? private void button8_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? num = double.Parse(textBox1.Text);
? ? ? ? ? ? fuhao = '-';
? ? ? ? ? ? textBox1.Text = null;
? ? ? ? }
? ? ? ? // ×
? ? ? ? private void button12_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? num = double.Parse(textBox1.Text);
? ? ? ? ? ? fuhao = '×';
? ? ? ? ? ? textBox1.Text = null;
? ? ? ? }
? ? ? ? // ÷
? ? ? ? private void button20_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? num = double.Parse(textBox1.Text);
? ? ? ? ? ? fuhao = '÷';
? ? ? ? ? ? textBox1.Text = null;
? ? ? ? }
? ? ? ? // %
? ? ? ? private void button19_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? num = double.Parse(textBox1.Text);
? ? ? ? ? ? fuhao = '%';
? ? ? ? ? ? textBox1.Text = null;
? ? ? ? }
? ? ? ? // =
? ? ? ? private void button13_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? temp = double.Parse(textBox1.Text);
? ? ? ? ? ? switch (fuhao)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? case '+':
? ? ? ? ? ? ? ? ? ? num += temp;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case '-':
? ? ? ? ? ? ? ? ? ? num -= temp;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case '×':
? ? ? ? ? ? ? ? ? ? num *= temp;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case '÷':
? ? ? ? ? ? ? ? ? ? num /= temp;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? case '%':
? ? ? ? ? ? ? ? ? ? num %= temp;
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? textBox1.Text = num.ToString();
? ? ? ? ? ? fuhao = ' ';
? ? ? ? ? ? num = 0;
? ? ? ? ? ? temp = 0;
? ? ? ? }
? ? ? ? // 刪除
? ? ? ? private void button18_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (textBox1.Text.Length > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? textBox1.Text = textBox1.Text.Substring(0, textBox1.Text.Length - 1);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //清空
? ? ? ? private void button17_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? textBox1.Text = "";
? ? ? ? }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

封开县| 九龙县| 湘乡市| 宁强县| 左云县| 长春市| 石景山区| 曲周县| 定南县| 新宁县| 岚皋县| 石柱| 益阳市| 申扎县| 崇左市| 喀喇| 景泰县| 墨竹工卡县| 淮北市| 额尔古纳市| 鲁山县| 湖口县| 乡宁县| 甘孜| 会理县| 绵阳市| 长宁县| 蕲春县| 永丰县| 铜陵市| 石楼县| 阳山县| 化隆| 光泽县| 靖州| 广州市| 镇雄县| 拜泉县| 平阳县| 焦作市| 施秉县|