I created an object in on event, now I want another event to access it. How do I do this?
I’m doing this in Visual Studio 2010.
I have a form that has three button events. The first button creates an object. I want the second button to use the object. How do I do this?
public void buttonCreate_Click(object sender, EventArgs e)
{
int size;
int sizeI;
string inValue;
inValue = textBoxSize.Text;
size = int.Parse(inValue);
inValue = comboBoxSizeI.Text;
sizeI = int.Parse(inValue);
Histrograph one = new Histrograph(size, sizeI);
}
public void buttonAddValue_Click(object sender, EventArgs e)
{
int dataV = 0;
string inValue;
inValue = textBoxDataV.Text;
dataV = int.Parse(inValue);
one.AddData(dataV); //using the object
}
If I parse your question correctly, you want to use the
onevariable created inbuttonCreate_ClickinbuttonAddValue_Click.To accomplish this you need to make
onea class variable, as in: