mercredi 26 avril 2017

i want to know exactly how i can use dialogresult and if

I just started study programming C#.. Below is my first programming project help me I don't know how can i fix it......

private void EXITBUTTON_Click(object sender, EventArgs e) { // Dialog box with two buttons : Yes and no. DialogResult dialogresult = MessageBox.Show("Do you really want to exit the program?", MessageBoxButtons.YesNo); if (dialogresult == DialogResult.Yes) { // ... } else (dialogresult == DialogResult.No); { // .... } }

    private void CLEARBOTTON_Click(object sender, EventArgs e)
    {
        //clear the textboxes.
        PriceTextBox.Text = "";
        DiscountPercentTextBox.Text = "";
        DiscountAmountTextBox.Text = "";
        TotalTextBox.Text = "";
        //reset all calculations.
    }

    private void DiscountPercentTextBox_TextChanged(object sender, EventArgs e)
    {

    }

    private void CALCULATEBUTTON_Click(object sender, EventArgs e)
    {
        try
        {
            int price;               // The input price
            int discountpercent;     // The discount percentage
            int discountamount;      // The amount of discount
            int total;               // The total price after discounting

            // Get the price.
                 price = int.Parse(PriceTextBox.Text);

            // Get the discount percentage.
                 discountpercent = int.Parse(DiscountPercentTextBox.Text);

            // Determine the discountpercent.
            if(price < 100)
            {
                // Display the discountpercent
                DiscountPercentTextBox = "1.00%";

                // Calculate discountamount.
                discountamount = price * 0.01;

                // Calculate Total
                total = price - discountamount;
            }
            else if(price < 200)
            {
                // Display the discountpercent
                DiscountPercentTextBox = "2.00%";

                // Calculate discountamount.
                discountamount = price * 0.02;

                // Calculate Total
                total = price - discountamount;
            }
            else if(price < 300)
            {
                // Display the discountpercent
                DiscountPercentTextBox = "3.00%";

                // Calculate discountamount.
                discountamount = price * 0.03;

                // Calculate Total
                total = price - discountamount;
            }
            else
            {
                // Display the discountpercent
                DiscountPercentTextBox = "4.00%";

                // Calculate discountamount.
                discountamount = price * 0.04;

                // Calculate Total
                total = price - discountamount;
            }

            // Display the total price.

        }
     catch
        {
            // Display an error message.
            MessageBox.Show("Please enter a valid input");

Aucun commentaire:

Enregistrer un commentaire