C#中从一个Form中启动另一个Form

Form1中有一个Button2

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.IsMdiContainer = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = "hello , you are my love";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();  //调用Form1的Hide()方法隐藏Form1窗口
            Form2 form2 = new Form2(); //生成一个Form2对象
            form2.ShowDialog();  //将Form2窗体显示为模式对话框。
            this.Close(); //关闭From1窗体。
        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //Form2 form2 = new Form2();
            //form2.ShowDialog();
            //form2.Dispose();
        }
    }
}

 

你可能感兴趣的:(object,C#,Class,button,textbox)