显示和隐藏窗体 不能显示第二个窗体
做二个窗体,通过点一窗体里的按钮来显示二窗体
出错不能显示二窗体,说
从未对字段“小项目.Form1.Form2Example”赋值,字段将一直保持其默认值 null
=============================================
一窗体代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 小项目
{
public partial class Form1 : Form
{
private Form2 Form2Example;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Rectangle pos = new Rectangle(250,250,300,300);
Bounds = pos;
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
Form2Example.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
{
Form2Example.Visible = false;
}
}
}
==========================
二窗体如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 小项目
{
public partial class Form2 : Form