0

I make a button that create a new form and pass to it an array but there is an error there is the code

int [] x=new int[9];
x={0,1,2,3,4,5,6,7,8};
form1 x =new form1(x);

and the other form constructor code is

public form1(int[]x)
        {
           InitializeComponent();
        }
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by sknake
0

The visual studio designer reflects controls with the parameterless constructor to render the control in the IDE. You should always chain your constructors and have a public parameterless constructor which will render a valid control.

For your form:

public partial class Form1 : Form
  {
    private int[] _array;

    public Form1()
    {
      InitializeComponent();
    }
    public Form1(int[] arr)
      : this()
    {
      this._array = arr;
    }

For your button:

private void button1_Click(object sender, EventArgs e)
    {
      int[] intArray = new int[] { 1, 2, 3, 4 };
      using (Form1 frm = new Form1(intArray))
      {
        frm.ShowDialog();
      }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.