المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to use public int?!!?!!? windows form.



C# Programming
07-16-2009, 10:40 AM
Hello All

I`m very new to the programming so this might be easy question to all of you, i`m hoping someone can help me out.

So i`m trying to write very easy program in windows form but i have encountered the problem.

lets say that i have an event on the button1 (CLICK) which should pick up a random number and hold it in the memory unless i click it again to change it. My problem is that i cannot figure out how to use this variable which has been set up in the first place with another event button2(Click) which will use this variable and do other task with using int previously declared. Short example:



public void Random_Click(object sender, EventArgs e)
{
Random myRandom = new Random();
int myNumber = myRandom.Next(1,10);
}
public void Button2_Click(object sender, EventArgs e)
{
MessageBox(myNumber.ToString());
}


This will not work and i cannot find the way to get it right

plese help !!!