zoukankan      html  css  js  c++  java
  • 动态创建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        }
  • 相关阅读:
    多环境
    Date的after()与before()方法的使用
    Centos6.8 yum报错及修复YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid
    JSON格式数据解析看这一个就足够了
    widnows下lua开发环境luadist LuaRocks搭建
    树的相关定义及遍历
    win10 启动redis服务的bat
    PageHelper分页失效的可能原因之一
    el-table多选表头复选框不对齐
    好用的软件推荐
  • 原文地址:https://www.cnblogs.com/wt0731/p/858618.html
Copyright © 2011-2022 走看看