显示和隐藏窗体 不能显示第二个窗体

骄傲青蛙 2007-04-21 11:30:21
做二个窗体,通过点一窗体里的按钮来显示二窗体


出错不能显示二窗体,说
从未对字段“小项目.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
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
Rectangle pos = new Rectangle(550, 250, 300, 300);
Bounds = pos;
}
}
}
...全文
244 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyun0112 2007-04-21
  • 打赏
  • 举报
回复
private Form2 Form2Example=new form2();
骄傲青蛙 2007-04-21
  • 打赏
  • 举报
回复
二楼对了,private Form2 Form2Example=new form2();


能帮我解释一下这个吗 不明白 为什么把对象pos赋给bounds
Rectangle pos = new Rectangle(250,250,300,300);
Bounds = pos;
gdx16659716 2007-04-21
  • 打赏
  • 举报
回复
private void button2_Click(object sender, EventArgs e)
{
Form2Example.Visible = true;
Form Form2Example = new Form2Example();
Form2Example.ShowDialog();//显示第二窗口
this.Close(); //关闭第一个窗口
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧