日期:2014-05-17  浏览次数:20856 次

如何实现动态弹出一个窗口里面显示其中一个 TabPage 的内容
Hi,

现在有一个 TabControl 在主界面显示,在 TabControl 里面有 3 个 TabPage ,

这个 TabControl 是隐藏的,同时,在主界面有一个 Button A ,

在 Button A 点击的时候,我想弹出一个窗口显示其中一个 TabPage,请问这个是否可以实现?

现在想实现动态弹出一个窗口里面显示其中一个 TabPage 的内容,不想手工又去创建一个 Form,简化流程。
同时,希望弹出窗口可以按要求调整下大小。

请指点一下,谢谢。


------解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnShowDlg_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            TabControl tc = new TabControl();
            tc.Size = this.tabControl1.Size;
            tc.TabPages.Add(this.tabPage1);
            f2.ItsControls.Add(tc);
            f2.ShowDialog();
            this.tabControl1.TabPages.Add(tc.TabPages[0]);
        }
    }
}


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

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public System.Windows.Forms.Control.ControlCollection ItsControls
        {
            get { return Controls;  }
        }

        public Form2()
        {
       &nbs