开始 private void MenuItem_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog();
    
        }
然后form2页面接收数据private void button1_Click(object sender, EventArgs e)
        {    
                Form1 f1 = new Form1(Convert.ToInt32(txt_long.Text), Convert.ToInt32(txt_wide.Text), Convert.ToInt32(txt_mine.Text));
                this.DialogResult = DialogResult.OK;
        }form1构造函数 public Form1(int x,int y,int z)
        {
            longs = x;
            wide = y;
            mine = z;
            btn();
        }
btn方法 public void btn()
        {
            this.label1.Location = new System.Drawing.Point(Convert.ToInt32(Width* 0.02), 17);
            this.label2.Location = new System.Drawing.Point(Convert.ToInt32(Width * 0.02) + 34, 19);
            this.label3.Location = new System.Drawing.Point(Convert.ToInt32(Width* 0.45), 17);
            this.label4.Location = new System.Drawing.Point(Convert.ToInt32(Width * 0.45) + 34, 19);
}

            this.label1.Location = new System.Drawing.Point(Convert.ToInt32(Width* 0.02), 17);
这句错误未将对象引用设置到对象的实例。
问下要怎么弄啊?。。

解决方案 »

  1.   

    Form1的label1还没有初始化呢。
    改成这样public Form1(int x,int y,int z)
            {
                InitializeComponent();
                longs = x;
                wide = y;
                mine = z;
                btn();
            }
      

  2.   

    public Form1(int x,int y,int z)
      {
      InitializeComponent();
      longs = x;
      wide = y;
      mine = z;
      btn();
      }