#How do I call a method from a click event?

11 messages · Page 1 of 1 (latest)

vocal raft
#

I have no idea what I am doing because I spent too much time on Java

namespace Retail_Price_Calculator
{
    public partial class Form1 : Form
    {
        double retailPrice;
        public Form1()
        {
            InitializeComponent();
        }

    private double CalculateRetail(double pCost, double pPercent)
        {
            return retailPrice = pCost + (pCost * pPercent);
        }

    private void calculateButton_Click(object sender, EventArgs e)
        {
            CalculateRetail(wholesaleCostTextBox.Text, markupPercentageTextBox.Text);
            retailPrice.ToString("c");
            displayPriceLabel.Text = "Retail Price: " + retailPrice;
        }
    }
}```
vocal raft
#
{
    public partial class Form1 : Form
    {
        double pCost;
        double pPercent;
        double retailPrice;
        public Form1()
        {
            InitializeComponent();
        }

    private double CalculateRetail(double pCost, double pPercent)
        {
            pCost = double.Parse(wholesaleCostTextBox.Text);
            pPercent = double.Parse(markupPercentageTextBox.Text);
            return retailPrice = pCost + (pCost * pPercent);
        }

    private void calculateButton_Click(object sender, EventArgs e)
        {
            double retailPrice = CalculateRetail(pCost, pPercent);
            retailPrice = retailPrice.ToString("c");
            displayPriceLabel.Text = "Retail Price: " + retailPrice;
        }
    }
}```
#

Idk how to convert it into a string and get it to display in displayPriceLabel

vocal raft
#

It works now but I had to start a new project so it had to be something in the designer

#

It's not calculating right

vocal raft
#

How do I turn the pPercent into a percent so that inserting 50 into markupPercentageTextBox is seen as 0.50 by the program?

proven wagon
vocal raft
#

It's C#

#

And I solved it already

proven wagon
#

mb i need sleep again

proven wagon