juncaixingchilove 2016-03-04 08:53 采纳率: 0%
浏览 1505

winform两页面传值时出现 未将对象引用设置到对象的实例

Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace adventure
{
public partial class Form1 : Form
{
string str1;
string str2;
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        //string str1 = Process.GetCurrentProcess().MainModule.FileName;
        OpenFileDialog open = new OpenFileDialog();
        if (open.ShowDialog() == DialogResult.OK)
        {
            textBox1.Text =open.FileName;
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        str1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;//得到路径
        textBox1.Text = str1;//显示得到的路径

    }

    private void button3_Click(object sender, EventArgs e)
    {
        str2 = textBox2.Text;
        Form2 f = new Form2(str1,str2); //将值传到Form2
        f.Show();
        //Form2 Form1 = new Form2();
        //在新弹出的窗口中显示得到的路径和内存
        //MessageBox.Show("您选择的文件路径是:\n" + textBox1.Text + "\n内存是:" + textBox2.Text);
        //Form1.Show();
    }
}

}

Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace adventure
{
public partial class Form2 : Form
{
string b;
string d;
public Form2(string a,string c)//a等同于Form1textbox值
{
this.b = a; //将Form1的textbox值传给b
this.d = c;
label1.Text = a;
label2.Text = c;
}

    public Form2()
    {
        // TODO: Complete member initialization
    }





}

}
图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2016-03-04 08:56
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划