You are viewing our Forum Archives. To view or take place in current topics click here.
[C#] How Can I Refer To Items On Previous Forms?
Posted:
[C#] How Can I Refer To Items On Previous Forms?Posted:
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
okay so i have come across this problem before but couldnt find a way to fix it.
so i created a checkbox on form 1, but when i tick it, i want it to display something on form2. now the problem is when i got to the form2 to write the if statement it doesnt give me the options to select the items on form1. so do i need to add a "using" statement at the top of the form or something? please help.
Thanks
so i created a checkbox on form 1, but when i tick it, i want it to display something on form2. now the problem is when i got to the form2 to write the if statement it doesnt give me the options to select the items on form1. so do i need to add a "using" statement at the top of the form or something? please help.
Thanks
#2. Posted:
Status: Offline
Joined: Jun 12, 201014Year Member
Posts: 531
Reputation Power: 33
So, what I think would be a better solution is to make a function public on form2 so that when you check the checkbox on form1, you can just call to it instead of having to make a thread on form2 to constantly check form1, etc.
You should make the form2 var global on form1 so it'd look like this:
Then wherever you show form2 or whatever it is you're doing, you should do:
Now, getting down to whatever on Form2. On Form2, you have the stuff you want to do if the checkbox is checked, right? So put that in a function like so:
Now finally, on the checkbox_click event, put this code:
You should make the form2 var global on form1 so it'd look like this:
Form2 xForm2;
// Form1 constructor should already be here
public Form1()
{
initializecomponent(); // etc.
}
Then wherever you show form2 or whatever it is you're doing, you should do:
xForm2 = new Form2();
Now, getting down to whatever on Form2. On Form2, you have the stuff you want to do if the checkbox is checked, right? So put that in a function like so:
public void PerformCheckboxEvents(bool IsChecked) // some name like that
{
if (IsChecked)
{
// stuff you want to happen when the checkbox is checked!
return;
}
// Stuff you want to happen when the checkbox ISN'T checked
}
Now finally, on the checkbox_click event, put this code:
if (xForm2 != null) // make sure that xForm2 has been initialized first!
{
xForm2.PerformCheckboxEvents(checkBox.Checked);
}
else
{
// xForm2 wasn't initialized, put error handling here.
}
- 4useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
thank you very much! also i have another problem (i know i have been asking a lot of questions lately but google just isnt as helpful as i thought it would be) probably because i dont know how to word this:
i have 2 textbox's:
textbox1 and textbox2
now i want to set the size of a button (button1) when i click button 2, after entering the x and y coordinates in textbox1 and textbox2.
so here is what i have tried
button1.location = (textbox1.text, textbox2.text); //this gave me an error
then i tried several more things like:
button1.location.x = (textbox1.text);
button1.location.y = (textbox2.text);
//error
button1.location = new point (textbox1.text, textbox2.text)
//error
when i try the one above ^^^ it tells me to enter int values, so how could i convert the textbox1.text int an int value?
i have tried:
int textbox1;
ect, ect
so to sum it all up i want to change the size of button1 by tying in the x (textbox1) and y(textbox2) coordinates and then clicking on button2. to change it.
Sorry if it doesnt really make sense this is the best i can explain it!
Thank You
i have 2 textbox's:
textbox1 and textbox2
now i want to set the size of a button (button1) when i click button 2, after entering the x and y coordinates in textbox1 and textbox2.
so here is what i have tried
button1.location = (textbox1.text, textbox2.text); //this gave me an error
then i tried several more things like:
button1.location.x = (textbox1.text);
button1.location.y = (textbox2.text);
//error
button1.location = new point (textbox1.text, textbox2.text)
//error
when i try the one above ^^^ it tells me to enter int values, so how could i convert the textbox1.text int an int value?
i have tried:
int textbox1;
ect, ect
so to sum it all up i want to change the size of button1 by tying in the x (textbox1) and y(textbox2) coordinates and then clicking on button2. to change it.
Sorry if it doesnt really make sense this is the best i can explain it!
Thank You
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Aug 15, 201013Year Member
Posts: 161
Reputation Power: 6
Status: Offline
Joined: Aug 15, 201013Year Member
Posts: 161
Reputation Power: 6
Vectorizing wrote thank you very much! also i have another problem (i know i have been asking a lot of questions lately but google just isnt as helpful as i thought it would be) probably because i dont know how to word this:
i have 2 textbox's:
textbox1 and textbox2
now i want to set the size of a button (button1) when i click button 2, after entering the x and y coordinates in textbox1 and textbox2.
so here is what i have tried
button1.location = (textbox1.text, textbox2.text); //this gave me an error
then i tried several more things like:
button1.location.x = (textbox1.text);
button1.location.y = (textbox2.text);
//error
button1.location = new point (textbox1.text, textbox2.text)
//error
when i try the one above ^^^ it tells me to enter int values, so how could i convert the textbox1.text int an int value?
i have tried:
int textbox1;
ect, ect
so to sum it all up i want to change the size of button1 by tying in the x (textbox1) and y(textbox2) coordinates and then clicking on button2. to change it.
Sorry if it doesnt really make sense this is the best i can explain it!
Thank You
Convert.Toint32(Textbox1.Text);
- 3useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
I_Rage_Hard wroteVectorizing wrote thank you very much! also i have another problem (i know i have been asking a lot of questions lately but google just isnt as helpful as i thought it would be) probably because i dont know how to word this:
i have 2 textbox's:
textbox1 and textbox2
now i want to set the size of a button (button1) when i click button 2, after entering the x and y coordinates in textbox1 and textbox2.
so here is what i have tried
button1.location = (textbox1.text, textbox2.text); //this gave me an error
then i tried several more things like:
button1.location.x = (textbox1.text);
button1.location.y = (textbox2.text);
//error
button1.location = new point (textbox1.text, textbox2.text)
//error
when i try the one above ^^^ it tells me to enter int values, so how could i convert the textbox1.text int an int value?
i have tried:
int textbox1;
ect, ect
so to sum it all up i want to change the size of button1 by tying in the x (textbox1) and y(textbox2) coordinates and then clicking on button2. to change it.
Sorry if it doesnt really make sense this is the best i can explain it!
Thank You
Convert.Toint32(Textbox1.Text);
here is what i did does it look right?
button1.Location = new Point (Convert.ToInt32(xSetInput.Text,(Convert.ToInt32(ySetInput.Text))));
it doesnt give me any errors so i will try it.
EDIT: i got an error saying invalid base so i will try it like so:
button1.Location = new Point (Convert.ToInt32(xSetInput.Text));
button1.Location = new Point(Convert.ToInt32(ySetInput.Text));
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Jun 12, 201014Year Member
Posts: 531
Reputation Power: 33
Vectorizing wrote
here is what i did does it look right?
button1.Location = new Point (Convert.ToInt32(xSetInput.Text,(Convert.ToInt32(ySetInput.Text))));
it doesnt give me any errors so i will try it.
EDIT: i got an error saying invalid base so i will try it like so:
button1.Location = new Point (Convert.ToInt32(xSetInput.Text));
button1.Location = new Point(Convert.ToInt32(ySetInput.Text));
Don't worry about asking questions, that's what we're here for
It looks like you forgot an ending parenthesis:
button1.Location = new Point (Convert.ToInt32(xSetInput.Text), Convert.ToInt32(ySetInput.Text));
- 1useful
- 0not useful
#7. Posted:
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
Status: Offline
Joined: Jun 10, 201014Year Member
Posts: 648
Reputation Power: 27
CLK wroteVectorizing wrote
here is what i did does it look right?
button1.Location = new Point (Convert.ToInt32(xSetInput.Text,(Convert.ToInt32(ySetInput.Text))));
it doesnt give me any errors so i will try it.
EDIT: i got an error saying invalid base so i will try it like so:
button1.Location = new Point (Convert.ToInt32(xSetInput.Text));
button1.Location = new Point(Convert.ToInt32(ySetInput.Text));
Don't worry about asking questions, that's what we're here for
It looks like you forgot an ending parenthesis:
button1.Location = new Point (Convert.ToInt32(xSetInput.Text), Convert.ToInt32(ySetInput.Text));
yup that made it work perfectly. and i really feel stupid for asking like 10 questions in a week. lol. its just hard to explain all that in 1 sentence so i could google search it. but anyway thanks a lot CLK and I_Rage_Hard! +rep for the both of you!
- 2useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.