• 动态创建TabPage



     
    1using System;
    2using System.Collections.Generic;
    3using System.ComponentModel;
    4using System.Data;
    5using System.Drawing;
    6using System.Text;
    7using System.Windows.Forms;
    1
      public partial class frmTabPage : Form
     2    {
     3        private TabControl tabControl1;
     4        private TabPage tabPage1;
     5        private TabPage tabPage2;
     6        private Button button1;
     7        private Button button2;
     8        public frmTabPage()
     9        {
    10            InitializeComponent();
    11            tabControl1 = new System.Windows.Forms.TabControl();
    12            tabPage1 = new System.Windows.Forms.TabPage();
    13            tabPage2 = new System.Windows.Forms.TabPage();
    14            button1 = new System.Windows.Forms.Button();
    15            button2 = new System.Windows.Forms.Button();
    16            this.CreateNewTabpage();
    17        }

    18  private void CreateNewTabpage()
    19        {          
    20            this.addPages(tabPage1, button1, "tabPage1");
    21            this.addPages(tabPage2, button2, "tabPage2");
    22            tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
    23        }

    24
    25        /// <summary>
    26        /// 动态创建TabPage
    27        /// </summary>
    28        /// <param name="tp">TabPage</param>
    29        /// <param name="btn">Button</param>
    30        /// <param name="sName">名称</param>

    31        private void addPages(TabPage tp, Button btn, string sName)
    32        {
    33            int i = 0;
    34            tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {tp});
    35            tp.Controls.AddRange(new System.Windows.Forms.Control[] { btn });
    36            tp.TabIndex = i;
    37            tp.Text = "动态创建" + sName;
    38            btn.Location = new System.Drawing.Point(6472);
    39            btn.Click += new System.EventHandler(this.button1_Click);
    40            btn.Text = "btn" + sName;
    41            btn.Width = 90;
    42            Controls.AddRange(new System.Windows.Forms.Control[] { tabControl1 });
    43            i = i + 1;
    44            tabControl1.TabIndex = 0;
    45            tabControl1.SelectedIndex = 0;// (TabPage.GetTabPageOfComponent(btn)).TabIndex;
    46            tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
    47        }

    48
    49        //添加事件
    50        private void button1_Click(object sender, EventArgs e)
    51        {
    52            MessageBox.Show("helloword!");
    53        }
  • 相关阅读:
    Oracle Autonomous Health Framework(AHF)
    Autonomous Health Framework(AHF)相关操作
    Postgresql 正则表达式
    如何去官网下载JDK (JDK8 JDK1.8)
    配置免安装版Oracle客户端
    子用户角色权限菜单 浅谈:子账户设计方案
    EF Power Tools Beta 2 生成 Entity Framework Code First 提示 参数错误 hresult e_invalidarg
    mvc 截取上传图片做头像,自动生成不同小尺寸缩略图
    亚马逊的下拉菜单插件 jQueryMenuAim 使用
    apacheab并发负载压力测试
  • 原文地址:https://www.cnblogs.com/wt0731/p/858618.html
Copyright © 2020-2023  润新知