欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

代碼:

Random rad = new Random(); // 實例化隨機對象
? ? ? ? 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 = "計算器";
? ? ? ? ? ? textBox1.ReadOnly =true;// 文本框無法輸入字符
? ? ? ? ? ? foreach (Control ctl in this.Controls)
? ? ? ? ? ? { ? // 獲取所有按鈕 ?改變背景顏色和數(shù)字和符號顏色
? ? ? ? ? ? ? ? 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;// 接收符號
? ? ? ? double temp, num; // temp第一個值,num為第二個值
? ? ? ?// 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";
? ? ? ? }
? ? ? ? //點
? ? ? ? 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)文章

  • C#中ListView用法實例

    C#中ListView用法實例

    我們經(jīng)常會在應(yīng)用程序中使用列表的形式來展現(xiàn)一些內(nèi)容,所以學(xué)好ListView是非常必需的,下面這篇文章主要給大家介紹了關(guān)于C#中ListView用法的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-06-06
  • Winform實現(xiàn)抓取web頁面內(nèi)容的方法

    Winform實現(xiàn)抓取web頁面內(nèi)容的方法

    這篇文章主要介紹了Winform實現(xiàn)抓取web頁面內(nèi)容的方法,代碼只有短短幾行,但是功能很實用,需要的朋友可以參考下
    2014-09-09
  • c# 使用handle.exe解決程序更新文件被占用的問題

    c# 使用handle.exe解決程序更新文件被占用的問題

    這篇文章主要介紹了c# 使用handle.exe解決程序更新文件被占用的問題,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • C#中4種深拷貝方法介紹

    C#中4種深拷貝方法介紹

    這篇文章主要介紹了C#中4種深拷貝方法介紹,本文講解了利用反射實現(xiàn)、利用xml序列化和反序列化實現(xiàn)、利用二進制序列化和反序列化實現(xiàn)、利用silverlight DataContractSerializer實現(xiàn),用于在silverlight 客戶端使用等4種方法,需要的朋友可以參考下
    2015-06-06
  • 為何Linq的Distinct實在是不給力

    為何Linq的Distinct實在是不給力

    本篇文章對Linq的Distinct進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • C#獲得MAC地址(網(wǎng)卡序列號)的實現(xiàn)代碼

    C#獲得MAC地址(網(wǎng)卡序列號)的實現(xiàn)代碼

    這篇文章主要介紹了C#獲得MAC地址的實現(xiàn)代碼,需要的朋友可以參考下
    2014-02-02
  • 使用windows控制臺調(diào)試服務(wù)的方法

    使用windows控制臺調(diào)試服務(wù)的方法

    這篇文章主要介紹了使用windows控制臺調(diào)試服務(wù)的方法,需要的朋友可以參考下
    2014-02-02
  • WinForm實現(xiàn)按名稱遞歸查找控件的方法

    WinForm實現(xiàn)按名稱遞歸查找控件的方法

    這篇文章主要介紹了WinForm實現(xiàn)按名稱遞歸查找控件的方法,需要的朋友可以參考下
    2014-08-08
  • 最新評論