I’m doing a project for college and have create a panel with a simple lunch menu. Each item of the menu if presented by a check box. What I wanted to happen was for the total to be changed every time a new item is checked or unchecked. This is the code I have tried using so far but it seems to freeze the program when I run it. I have tried using a while loop to constantly check if the check boxes are checked or un-checked.
There is a panel with the check boxes inside and a label at the bottom of the panel.
Am I on the right line in terms of using the while loop to check what the checked status of each check box is and update the label text accordingly?
private void plBistro_Paint(object sender, PaintEventArgs e)
{
//create a variable to hold the total
double bistotal = 0.0;
while(bistotal != 99){
//check if they chose a ham sandwich
if(cbHamSandwich.Checked == true){
//if they did add 1.20 to the value of bistotal
bistotal = bistotal + 1.20;
}
string bistotalString = Convert.ToString(bistotal);
lblBistroTotal.Text = bistotalString;
}
}
You have an infinite loop in your code, plus the Paint event is not the place to do this calculation. You want something more like:
Add
CheckChangedevents for each option that needs to change the total price.