Question regarding text boxes and button click events

Hello friends,

I've been on this adventure for a few months now, the course I'm learning C# in has recently migrated from command prompt based coding to application based coding. The transition has been a little difficult for me, admittedly. I really started to feel like I understood the basics, especially around collecting information, storing it as a variable and converting it to another data type. Without ReadLine, it's not occurring to me as intuitively. Any comments or tips on how to better understand it would definitely be appreciated. I'm working on an assignment to create two text boxes, and three buttons. One of the buttons, calculate, is supposed to take the two values entered into the text boxes. One of the values is sales tax amount, the other is how much the product cost. When I click calculate, the total cost is then supposed to be shown in a message box that uses the currency format. I was hoping someone might be able to assist where I'm going wrong.

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 WindowsFormsApplication3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void button3_Click(object sender, EventArgs e) { Close(); } private void clear_Click(object sender, EventArgs e) { Costbox.Text = (""); Salesbox.Text = (""); } private void Calc_Click(object sender, EventArgs e) { double cost = Convert.ToDouble(Costbox.Text); double tax = Convert.ToDouble(Salesbox.Text); double total = cost * tax; MessageBox.Show("The total cost is {0:C},", total); } } 

}

by Servatose via /r/csharp

Leave a Reply