开发者

winForms, help with converting text in txtbox to double if possible?

i have the below coding in winForms in 3 different btns.

I have very limited knowledge of winForms, as i mostly use Console applications, but i am trying to use text boxes and buttons and user input to create a program that calculates the price variations of a product.

basically i what i am strugglin开发者_如何学Pythong with is converting whatever is in a text box (usually doubles) to a given name to be used to perform calculations on and then append them to the next text box etc.

can anyone help me with this please? it would be much appreciated!

thank you!

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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public Form1 salePrice { get; private set; }
        public Form1 discountPrice { get; private set; }
        public Form1 vat { get; private set; }
        public Form1 onlyVat { get; private set; }
        public Form1 totalPrice { get; private set; }
        public Form1 changeGiven { get; private set; }
        public Form1 payment { get; private set; }

        private void calcPriceAndDiscount_Click(object sender, EventArgs e)
        {
            salePrice = PriceBox;
            discountPrice = DiscountBox;

            salePrice = (salePrice - discountPrice);

            SubtotalBox.AppendText(String.Format("{0:c}", salePrice));            
        }

        private void calcWithVat_Click(object sender, EventArgs e)
        {
            onlyVat = (salePrice / 100.00 * vat);
            totalPrice = (onlyVat + salePrice);

            totalPrice = FinalPriceBox;
            vat = VATBox;

            FinalPriceBox.AppendText(String.Format("{0:c}", totalPrice));
        }

        private void calcPaymentMinPrice_Click(object sender, EventArgs e)
        {
            changeGiven = (payment - totalPrice);

            payment = PaymentBox;

            ChangeGivenBox.AppendText(String.Format("{0:c}", changeGiven));
        }
    }
}


double dbl;
if (double.TryParse(TextBox1.Text, out dbl))
{
    // dbl contains the value of the text
}
else
{
    // The text could not be converted to a double
}

When you're done with the value:

TextBox1.Text = dbl.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜