C#设计程序购买商品总金额

这是实训二的题,也是比较简单的,适合我这样的才开始学的新手练手

这下面是效果图:在这里插入图片描述
还是和之前一样创建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();
        }
    }
}

我不是在简单的编程,而是在创造一个“世界”。
江客:时荒
  • 10
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值