第一个窗体关闭打开第二个窗体

King_NaNa King_NaNa 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace tree
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());//先启动2号窗体
}
}
}
************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tree
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
Form1 f1 = new Form1(this);//实例1号窗体,那里面的this有用什么用呢?
f1.ShowDialog(this);//这个地方什么要用ShowDialog,为什么要用Show(this)就不行呢?
}
}
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace tree
{
public partial class Form1 : Form
{
Form2 f2;
public Form1(Form2 f2)
{
this.f2 = f2;//这样有什么用处呢?
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}

private void button2_Click(object sender, EventArgs e)
{
this.textBox1.Clear();
this.textBox2.Clear();
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
f2.Show();
this.Close();
}
}
}
...全文
评论 5
收藏 已收藏
分享
返回顶部
King_NaNa
C# 111,129 成员 642,539 内容