这是实训二的题,也是比较简单的,适合我这样的才开始学的新手练手
这下面是效果图:
还是和之前一样创建Windo窗口应用,拖入Panel控件,然后再拖入3个button控件、4个text.Box、8个Label、1个LinkLabel。
话不多说下面是我写的代码,请多多指教:
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 购买商品总金额
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private float Zon() //总价值算法
{
int a=0, b=0, c=0, d=0;
float z;
//将输出的个数赋值到a,b,c,d;
a = Convert.ToInt32(textBox1.Text.ToString());
b = Convert.ToInt32(textBox2.Text.ToString());
c= Convert.ToInt32(textBox3.Text.ToString());
d = Convert.ToInt32(textBox4.Text.ToString());
z =(float) (60 * a + 50 * b + 2.5 * c + 3 * d);//这几个数字就是商品价格可以随时更改。
return z;
}
private void button1_Click(object sender, EventArgs e)
{
float z;
z = Zon();
MessageBox.Show("您购买商品的总价是:"+z.ToString());//代表将下一个窗口显示
}
private void button2_Click(object sender, EventArgs e)
{
//清除数字
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
//退出程序
Application.Exit();
}
}
}
我不是在简单的编程,而是在创造一个“世界”。
江客:时荒