C#實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器
本文實(shí)例為大家分享了C#實(shí)現(xiàn)簡(jiǎn)易的計(jì)算器的具體代碼,供大家參考,具體內(nèi)容如下
1 題目描述
(1)Form1窗體設(shè)計(jì)界面如下:

(2)運(yùn)算類型的下列列表中包括:加法、減法、乘法、除法、取模共5種操作;初始狀態(tài)下,選擇“加法”運(yùn)算,當(dāng)用戶更改運(yùn)算類型時(shí),下面式子中的加號(hào)“+”應(yīng)自動(dòng)更改為相應(yīng)的運(yùn)算符;
(3)當(dāng)用戶在前兩個(gè)文本框中輸入時(shí),最后得到結(jié)果的文本框始終是空白狀態(tài),注意該文本框是只讀的,用戶不能更改其值;只有當(dāng)用戶單擊確定按鈕時(shí),結(jié)果文本框中才會(huì)顯示正確的計(jì)算結(jié)果;
(4)使用過(guò)程中,用戶修改運(yùn)算類型時(shí),三個(gè)文本框的內(nèi)容自動(dòng)清空;
2 源碼詳解
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Csharp7_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
label3.Text = "+";
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
label3.Text = "-";
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked == true)
{
label3.Text = "*";
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
if (radioButton4.Checked == true)
{
label3.Text = "÷";
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
if (radioButton5.Checked == true)
{
label3.Text = "%";
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
textBox3.Text = Convert.ToString((int.Parse(textBox1.Text)) + (int.Parse(textBox2.Text)));
}
if (radioButton2.Checked == true)
{
textBox3.Text = Convert.ToString((int.Parse(textBox1.Text)) - (int.Parse(textBox2.Text)));
}
if (radioButton3.Checked == true)
{
textBox3.Text = Convert.ToString((int.Parse(textBox1.Text)) * (int.Parse(textBox2.Text)));
}
if (radioButton4.Checked == true)
{
textBox3.Text = Convert.ToString((double.Parse(textBox1.Text)) / (double.Parse(textBox2.Text)));
}
if (radioButton5.Checked == true)
{
textBox3.Text = Convert.ToString((int.Parse(textBox1.Text)) % (int.Parse(textBox2.Text)));
}
}
}
}
3 實(shí)現(xiàn)效果





以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C#編寫的windows計(jì)算器的實(shí)例代碼
- C#計(jì)算器編寫代碼
- C#實(shí)現(xiàn)簡(jiǎn)單的計(jì)算器功能完整實(shí)例
- C#開(kāi)發(fā)簡(jiǎn)易winform計(jì)算器程序
- C#實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能
- C#實(shí)現(xiàn)簡(jiǎn)單加減乘除計(jì)算器
- C#實(shí)現(xiàn)Winform版計(jì)算器
- C#實(shí)現(xiàn)的簡(jiǎn)單整數(shù)四則運(yùn)算計(jì)算器功能示例
- c#入門之實(shí)現(xiàn)簡(jiǎn)易存款利息計(jì)算器示例
- C# WinForm程序設(shè)計(jì)簡(jiǎn)單計(jì)算器
相關(guān)文章
C# Winfom 中ListBox的簡(jiǎn)單用法詳解
這篇文章主要介紹了C# Winfom 中ListBox的簡(jiǎn)單用法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Unity UGUI的RectMask2D遮罩組件的介紹使用
這篇文章主要為大家介紹了Unity UGUI的RectMask2D遮罩組件的介紹使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
C# 獲取當(dāng)前月份天數(shù)的三種方法總結(jié)
本篇文章主要是對(duì)C#中獲取目前月份的天數(shù)的三種方法進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01
詳解C#如何實(shí)現(xiàn)隱式類型轉(zhuǎn)換
Result?類型是許多編程語(yǔ)言中處理錯(cuò)誤的常用方式,包括?C#?的?dotNext?庫(kù)。在本文中,我們將通過(guò)例子回顧?C#?中?using?語(yǔ)句和隱式類型轉(zhuǎn)換的使用,感興趣的可以了解一下2023-01-01
C# 時(shí)間與時(shí)間戳互轉(zhuǎn)的方法(13位)
這篇文章主要介紹了C# 時(shí)間與時(shí)間戳互轉(zhuǎn)的方法(13位),詳細(xì)的介紹了常出現(xiàn)的幾種時(shí)間方式及其時(shí)間與時(shí)間戳互轉(zhuǎn)的方法,非常具有實(shí)用價(jià)值,希望此文章對(duì)各位有所幫助2018-10-10
C#使用IComparer自定義List類實(shí)現(xiàn)排序的方法
這篇文章主要介紹了C#使用IComparer自定義List類實(shí)現(xiàn)排序的方法,涉及C#使用IComparer接口定義List類進(jìn)行排序的相關(guān)技巧,需要的朋友可以參考下2015-08-08
WPF ComboBox獲取當(dāng)前選擇值的實(shí)例詳解
這篇文章主要介紹了WPF ComboBox獲取當(dāng)前選擇值的實(shí)例詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-01-01

