- 等差相加( textBox1 累加到 textBox2)
- 等差相乘( textBox1 累乘到 textBox2)
檔案 → 新增專案 → Windows Form 應用程式 → 拉物件 Form1.cs[設計] → 撰寫 Form1.cs
拉入 Windows Form :
- textBox × 4
- Label × 5
- button × 1
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 test2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int sum=0, inputA, inputB;
long multiplied = 1;
inputA = int.Parse(textBox1.Text);
inputB = int.Parse(textBox2.Text);
for (int i = inputA; i <= inputB; i++)
{
sum = sum + i;
}
for (int j = inputA; j <= inputB; j++)
{
multiplied = multiplied * j;
}
textBox3.Text = sum.ToString();
textBox4.Text = multiplied.ToString();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
沒有留言:
張貼留言