Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

Why Isn't this working! *** Solved! ***

This topic is 4864 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

Why won't this work?
Int32 tempX = Convert::ToInt32(x);
tempX --;
String *tempString = String::Concat("pictureBox",Convert::ToString(tempX),"_2");
System::Object *myObj = (System::Object *)tempString;
((System::Windows::Forms::PictureBox *)myObj)->BackColor = Color::Red;






What it's supposed to do is convert the name of a control in my windows form from a string format, to a system object so that I can then manipulate it's properties. I can't just take It's name and start fidelling with it because it changes based upon things that the user does in the form. How can I fix this code? [Edited by - Zmurf on July 24, 2005 12:20:56 AM]

Share this post


Link to post
Share on other sites
Advertisement
Ok I have a new problem, this is the code I'm using to compare the string I have for the controls name and the currently selected control name in the loop:

private: System::Void pictureBoxGlobal_Click(System::Object *  sender, System::EventArgs *  e){
System::Windows::Forms::PictureBox *tempControl = (System::Windows::Forms::PictureBox *)sender;
String *x = tempControl->Name->Substring(10,1);
String *y = tempControl->Name->Substring(12,1);
if (!String::Compare(x,"1") || !String::Compare(y,"1")
|| !String::Compare(x,"7") || !String::Compare(y,"7")){
tempControl->BackColor = Color::Red;
}
else {
String *tempString = tempControl->Name->ToString();
Int32 controlCount = frmMain::Controls->get_Count();
for (Int32 i = 1; i < controlCount; i++){
String *controlName = frmMain::Controls->get_Item(i)->Name->ToString();
if (controlName->CompareTo(tempString) == 0){
MessageBox::Show(controlName);
break;
}
}
}
}


This is the entire function. The code in the if {} braces are irelivent. It is the else {} code i'm having trouble with.

[Edited by - Zmurf on July 23, 2005 10:32:44 PM]

Share this post


Link to post
Share on other sites
It's not working lol. I've tried all diferent methods of comparing the two strings to see if they match:

if (!String::Compare(controlName, tempString))
if (controlName == tempString)
if (controlName->CompareTo(tempString) == 0)

But it never works. Now i'm thinking that maybe the control count isn't coded properly or maybe handelling the currently selected item in the loop is wrong. Does anything stand out in the code?

Share this post


Link to post
Share on other sites
Ok I was running a few tests on it, and I found that:

Int32 controlCount = this->Controls->get_Count();

returns 33 controls, when I have atleast 50 since there is a 7 by 7 grid of picture boxes that the game board is played on. How can I get this to work correctly?

[Edit]: Ok i've figured it out, It's because i only hae 3 group boxes inside my form, and the other controls are inside the group box, not my forms, so i needed to say:

this->groupBoxGame->Controls->get_Count();

Now it works fines. Thanks for your help.

[Edited by - Zmurf on July 24, 2005 12:51:39 AM]

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!