.NET練習平方根計算
1447 ワード
1.Windowsフォームを新規作成2.フォームにコントロールを追加:TextBox(テキストボックス)、Button(ボタン)、Label(ラベル)3.Buttonオブジェクトにクリックイベントコードを追加
クリックイベントコード設計の考え方
①テキストボックスから入力した文字列を取得②取得した文字列を強制的にテキストタイプに変換③平方根を計算する関数sqrt()で計算④計算結果をLabelタグに表示する位置へ出力
ソースコード
プロセス中に発生した問題
①テキストボックスから文字列の構文形式を取り込む②型変換を強制する方法③sqrt()関数を用いた形式④結果を表示する構文形式
参考内容
テキストボックスから文字列を取り込む:『WinFormプログラム設計と実践』P 200強制タイプ変換:(https://www.cnblogs.com/smart-can/p/4478799.html)Labelラベルに内容を表示する:(https://zhidao.baidu.com/question/1429568861139651059.html)
クリックイベントコード設計の考え方
①テキストボックスから入力した文字列を取得②取得した文字列を強制的にテキストタイプに変換③平方根を計算する関数sqrt()で計算④計算結果をLabelタグに表示する位置へ出力
ソースコード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Num ,texNum ,textNum.Text ,Convert.ToInt32
int Num = Convert.ToInt32(textNum.Text);
//label1
result.Text = (Math.Sqrt(Num)).ToString();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
プロセス中に発生した問題
①テキストボックスから文字列の構文形式を取り込む②型変換を強制する方法③sqrt()関数を用いた形式④結果を表示する構文形式
参考内容
テキストボックスから文字列を取り込む:『WinFormプログラム設計と実践』P 200強制タイプ変換:(https://www.cnblogs.com/smart-can/p/4478799.html)Labelラベルに内容を表示する:(https://zhidao.baidu.com/question/1429568861139651059.html)