最新国产好看的视频,伊人天堂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ī)對(duì)象
? ? ? ? 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;// 文本框無(wú)法輸入字符
? ? ? ? ? ? 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 = "";
? ? ? ? }

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

相關(guān)文章

最新評(píng)論

河源市| 咸阳市| 壤塘县| 左云县| 阿克| 柘城县| 兴隆县| 石屏县| 台安县| 原阳县| 博罗县| 盈江县| 马尔康县| 衡阳市| 合水县| 维西| 开平市| 茂名市| 庆元县| 香格里拉县| 泰来县| 久治县| 三门峡市| 澄江县| 昭通市| 北票市| 横峰县| 德化县| 湛江市| 固阳县| 乡宁县| 思南县| 塔城市| 商河县| 易门县| 榆林市| 剑阁县| 灵石县| 辰溪县| 文登市| 吐鲁番市|