ni*********@hot mail.com wrote:
I need to get int1 int2 and int3 from
"private void button1_Click(o bject sender, System.EventArg s e)" in
form1 to
public form2();
In form2 i will need to use each variable in public form2 rather than a
specific object further down the code
i was previously using the contructor tutorial i found here
http://www.codeproject.com/useritems...ween_forms.asp
but could not work out how to send multiple integers
Im sorry if this is still pretty vague! im still getting the hang of
this!
So create a constructor for form2 that either takes in four integers, an int
array, or possibly a struct that has the integers as properties. The last
approach gives you the most flexibility in that you can add additional items
to the struct without changing your constructor signature. But use
whichever best fits the needs of your particular problem. Exs:
public Form2()
{
InitializeCompo nent();
}
// constructor that takes in four ints
public Form2(int val1, int val2, int val3, int val4) : this()
{
// set values based on ints passed in
control1.Value = int1;
control2.Values = int2;
//etc...
}
// constructor that takes an int[]
public Form2(int [] vals) : this()
{
control1.Value = vals[0];
control2.Value = vals[1];
//etc...
}
// create a struct to be used for passing data into the form
// refine to have private fields with public accessors
public struct Form2Data
{
public int val1;
public int val2;
public int val3;
public int val4;
}
// constructor that takes in the data in a struct
public Form2(Form2Data data) : this()
{
control1.Value = data.val1;
control2.Value = data.val2;
//etc...
}
--
Tom Porterfield