Difficulty displaying text to a label

Hello, I feel as though it's appropriate to preface this with stating that I'm a complete newbie to C#. I only just started using an IDE for basic application development for some coursework. I'm having trouble understanding why I can't get text to display to a label correctly.

 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 CarOptions { public partial class CarOptions : Form { public CarOptions() {

 InitializeComponent(); } private void btnCalc_Click(object sender, EventArgs e) { double dblCar = 15000; if (chkAC.CheckState == CheckState.Checked) { dblCar = dblCar + 750; return; } if (chkMP3.CheckState == CheckState.Checked) { dblCar = dblCar + 250; return; } if (chkWindows.CheckState == CheckState.Checked) { dblCar = dblCar + 500; return; } if (chkWindows.CheckState == CheckState.Indeterminate) { MessageBox.Show("You must make a choice for power windows", "Missing Entry"); return; } if (chkMP3.CheckState == CheckState.Indeterminate) { MessageBox.Show("You must make a choice for audio", "Missing Entry"); return; } if (chkAC.CheckState == CheckState.Indeterminate) { MessageBox.Show("You must make a choice for AC", "Missing Entry"); return; } lblTotal.Text = (String.Format("{0:C}", dblCar)); } } } 

Now, the trouble seems to be with lblTotal.Text = String.Format("{0:C}", dblCar);

By putting this code at the top of the click button event, where I declare my variables It causes the calculate button to trigger $15,000.00 to be displayed, but when I put it at the bottom of the code like I show in this example, nothing shows up. I click calculate and nothing happens. I've looked at this for a long while and can't seem to figure out why I'm having difficulties with this. Any guidance would be appreciated.

by Servatose via /r/csharp

Leave a Reply