• Advertisement
Sign in to follow this  

Moving Variables (C#)

This topic is 4710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am still working on a game. I have almost gotten to the point of where my code works, but now I am stumped. -I want it so that when the Item is clicked it turns red, meaning its selected. I got that done. -But then I wanted the user to be able to move their items wherever they wanted, but if you click more then two different spots. The quantity doesn't seem to keep up. Here is my code: private void lblItem1_Click(object sender, System.EventArgs e) { if (lblItem1.Text == "-----") { lblItem1.Text = SelectedItem; lblQuantity1.Text = SelectedQuantity.ToString(); if (lblItem1.BackColor == Color.Red) { lblItem1.Text = "-----"; Quantity1 = 0; lblQuantity1.Text = Quantity1.ToString(); } else if (lblItem2.BackColor == Color.Red) { lblItem2.Text = "-----"; Quantity2 = 0; lblQuantity2.Text = Quantity2.ToString(); } else if (lblItem3.BackColor == Color.Red) { lblItem3.Text = "-----"; Quantity3 = 0; lblQuantity3.Text = Quantity3.ToString(); } else if (lblItem4.BackColor == Color.Red) { lblItem4.Text = "-----"; Quantity4 = 0; lblQuantity4.Text = Quantity4.ToString(); } else if (lblItem5.BackColor == Color.Red) { lblItem5.Text = "-----"; Quantity5 = 0; lblQuantity5.Text = Quantity5.ToString(); } else if (lblItem6.BackColor == Color.Red) { lblItem6.Text = "-----"; Quantity6 = 0; lblQuantity6.Text = Quantity6.ToString(); } else if (lblItem7.BackColor == Color.Red) { lblItem7.Text = "-----"; Quantity7 = 0; lblQuantity7.Text = Quantity7.ToString(); } else if (lblItem8.BackColor == Color.Red) { lblItem8.Text = "-----"; Quantity8 = 0; lblQuantity8.Text = Quantity8.ToString(); } else if (lblItem9.BackColor == Color.Red) { lblItem9.Text = "-----"; Quantity9 = 0; lblQuantity9.Text = Quantity9.ToString(); } else if (lblItem10.BackColor == Color.Red) { lblItem10.Text = "-----"; Quantity10 = 0; lblQuantity10.Text = Quantity10.ToString(); } else if (lblItem11.BackColor == Color.Red) { lblItem11.Text = "-----"; Quantity11 = 0; lblQuantity11.Text = Quantity11.ToString(); } else if (lblItem12.BackColor == Color.Red) { lblItem12.Text = "-----"; Quantity12 = 0; lblQuantity12.Text = Quantity12.ToString(); } else if (lblItem13.BackColor == Color.Red) { lblItem13.Text = "-----"; Quantity13 = 0; lblQuantity13.Text = Quantity13.ToString(); } else if (lblItem14.BackColor == Color.Red) { lblItem14.Text = "-----"; Quantity14 = 0; lblQuantity14.Text = Quantity14.ToString(); } else if (lblItem15.BackColor == Color.Red) { lblItem15.Text = "-----"; Quantity15 = 0; lblQuantity15.Text = Quantity15.ToString(); } else if (lblItem16.BackColor == Color.Red) { lblItem16.Text = "-----"; Quantity16 = 0; lblQuantity16.Text = Quantity16.ToString(); } } lblItem16.BackColor = Color.Gray; lblItem15.BackColor = Color.Gray; lblItem14.BackColor = Color.Gray; lblItem13.BackColor = Color.Gray; lblItem12.BackColor = Color.Gray; lblItem11.BackColor = Color.Gray; lblItem10.BackColor = Color.Gray; lblItem9.BackColor = Color.Gray; lblItem8.BackColor = Color.Gray; lblItem7.BackColor = Color.Gray; lblItem6.BackColor = Color.Gray; lblItem5.BackColor = Color.Gray; lblItem1.BackColor = Color.Red; lblItem2.BackColor = Color.Gray; lblItem3.BackColor = Color.Gray; lblItem4.BackColor = Color.Gray; ItemNumber = "1"; Item1 = lblItem1.Text; SelectedItem = lblItem1.Text; SelectedQuantity = Quantity1; } Any ideas? (There are 15 other click events for the other labels. Just didn't want to post all that code.)

Share this post


Link to post
Share on other sites
Advertisement
to start with, if you want more people to help you use source tags like this
[ source ]


class NiceFormattedCode
{
public:
bool IsReadable() { return true; }
};



[ /source ]

just remove the spaces. Can't help you with your prob, but proper formatting will encourage others

Share this post


Link to post
Share on other sites
Sorry, I normally do, but most forums that I got to, have little buttons to show me how or add them for me.

I figured it out. With the SelectedItem = lblItem.Text;

But with the Quantity i was setting it equal to a variable. So i just made it equal to lblQuantity.Text.

Thanks though anyways.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement