zl程序教程

您现在的位置是:首页 >  后端

当前栏目

c#子窗口与父窗口_主窗体控制子窗体的显示

c#控制 显示 窗口 窗体
2023-06-13 09:11:03 时间

大家好,又见面了,我是你们的朋友全栈君。

方法较为简单,直接撸代码

父窗口代码

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();
        }

        private void button1_Click(object sender, EventArgs e)
        { 
   
            Form2 f2 = new Form2(this);
            f2.Show();
            this.Hide();
        }
    }
}

子窗口代码

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 Form2 : Form
    { 
   
        public Form1 prof1;
        public Form2(Form1 f1)
        { 
   
            InitializeComponent();
            prof1 = f1;
        }

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

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/170914.html原文链接:https://javaforall.cn