C〓〓は簡易な計算機を実現します。
本論文の例では、簡単な計算機の具体的なコードを共有しました。参考にしてください。具体的な内容は以下の通りです。
1テーマの説明
(1)フォームデザイン画面は以下の通りです。
(2)演算タイプの次のリストには、加算、減算、乗算、除算、型取りの5つの動作があります。初期状態では、「加算」演算を選択します。ユーザーが演算タイプを変更すると、下の式の「+」は自動的に演算子に変更されます。
(3)前の2つのテキストボックスにユーザーが入力した場合、最後に結果を得たテキストボックスは常に空白状態です。テキストボックスは読み取り専用で、ユーザーはその値を変更できません。ユーザーが決定ボタンをクリックした場合のみ、結果テキストボックスに正しい計算結果が表示されます。
(4)使用中に、ユーザーが演算タイプを変更すると、3つのテキストボックスの内容が自動的に空になります。
2ソースコードの詳細
以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。
1テーマの説明
(1)フォームデザイン画面は以下の通りです。
(2)演算タイプの次のリストには、加算、減算、乗算、除算、型取りの5つの動作があります。初期状態では、「加算」演算を選択します。ユーザーが演算タイプを変更すると、下の式の「+」は自動的に演算子に変更されます。
(3)前の2つのテキストボックスにユーザーが入力した場合、最後に結果を得たテキストボックスは常に空白状態です。テキストボックスは読み取り専用で、ユーザーはその値を変更できません。ユーザーが決定ボタンをクリックした場合のみ、結果テキストボックスに正しい計算結果が表示されます。
(4)使用中に、ユーザーが演算タイプを変更すると、3つのテキストボックスの内容が自動的に空になります。
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実現効果以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。