Windows Develop Bookmark and Share   
 index > Windows Forms General > help plzzz, strange result
 

help plzzz, strange result

hi, i think found a bug in C# language. i have tried on C# express edition with SP1 and visual studio 2005 professional. here is:

this is my first code:
Code Snippet

switch (shipComboBox.SelectedIndex)
{
case 0:
weapon1Label.Text = "Canon";
weapon2Label.Text = "Missile";
break;
case 1:
weapon1Label.Text = "Big Laser";
weapon2Label.Text = "Gila";
break;
}

weapon1PictureBox.Image = System.Drawing.Bitmap.FromFile("..\\..\\Ship\\" + shipPic + "W1.jpg");
weapon2PictureBox.Image = System.Drawing.Bitmap.FromFile("..\\..\\Ship\\" + shipPic + "W2.jpg");


--------------------------------------------------------------------------------------------
this is my second code:
Code Snippet

weapon1PictureBox.Image = System.Drawing.Bitmap.FromFile("..\\..\\Ship\\" + shipPic + "W1.jpg");
weapon2PictureBox.Image = System.Drawing.Bitmap.FromFile("..\\..\\Ship\\" + shipPic + "W2.jpg");

switch (shipComboBox.SelectedIndex)
{
case 0:
weapon1Label.Text = "Canon";
weapon2Label.Text = "Missile";
break;
case 1:
weapon1Label.Text = "Big Laser";
weapon2Label.Text = "Gila";
break;
}



nah, you see those codes are the same. but it's only different at ordering only. the first code has a switch at above of weaponPictureBox, and the second the switch at below weaponPictureBox. my first code has good result, no problem. unfortunately my second code has a problem, when i choose shipComboBox.SelectedIndex to 1, the switch doesn't run a case 1. it's only run case 0 forever. i don't know what i'm wrong. can you explain what happened? thanks.

Note: even i tried in C# express edition SP1 and visual studio 2005 professional. it give the same result. and i have tried to change switch to if, same result as well
Klinci  Saturday, May 19, 2007 4:05 PM
Maybe its not the switch that is the problem but the screen updating. Once the screen is updated, does the combobox lose focus? Try capturing the value before assigning the images and using that in the switch.
OmegaMan  Saturday, May 19, 2007 5:02 PM

Hi,

did you step into the code with a debugger to confirm the values of the variables? How do you know it is not going into the correct case?

Mark.

Mark Dawson  Saturday, May 19, 2007 5:41 PM
Also maybe in the case should default and throw an exception...maybe there is a value coming through you are not expecting?
OmegaMan  Saturday, May 19, 2007 6:09 PM
Maybe its not the switch that is the problem but the screen updating. Once the screen is updated, does the combobox lose focus? Try capturing the value before assigning the images and using that in the switch.
OmegaMan  Saturday, May 19, 2007 5:02 PM

Hi,

did you step into the code with a debugger to confirm the values of the variables? How do you know it is not going into the correct case?

Mark.

Mark Dawson  Saturday, May 19, 2007 5:41 PM
Also maybe in the case should default and throw an exception...maybe there is a value coming through you are not expecting?
OmegaMan  Saturday, May 19, 2007 6:09 PM

You can use google to search for other answers

Custom Search

More Threads

• Quicktime ?
• Looking for a tooltip control that will contain a UserControl or a Form (c#/.net 2.0)
• font as Embedded Resource
• Button Control like VS File Open?
• Graphics list
• How do I SELECT formatted fileds in Access
• BackgroundWorker: Accessing data not passed in via RunWorkerAsynch
• DataGridView WrapMode Broken w/o Spaces
• Converted to 2008 - got MissingManifestResourceException
• A question about listview (C#)