Ir para conteúdo
Fórum Script Brasil
  • 0

Criar TabPage em tempo de execução


Adilson_web

Pergunta

Olá pessoal eu preciso criuar quantas TabPage for necessários, dependendo do calculo, essas tabPage irão aparecer no form para usuário.

Eu usei um for para criar mas não da certo, não da erro não acontece nada! Alguém pode me ajudar por favor?

int j = 1;
            for (int i = ano1; i >= ano2;i++ ) {
                this.tabControl2.Controls.Add(this.tabela+j  = new TabPage ());
                this.tabControl2.Location = new System.Drawing.Point(12, 12);
                this.tabControl2.Name = "tab";
                this.tabControl2.SelectedIndex = 0;
                this.tabControl2.Size = new System.Drawing.Size(268, 100);
                this.tabControl2.TabIndex = 0;

                this.tabela.Location = new System.Drawing.Point(4, 22);
                this.tabela.Name = "tabPage" + j;

                this.tabela.Padding = new System.Windows.Forms.Padding(3);
                this.tabela.Size = new System.Drawing.Size(260, 74);
                this.tabela.TabIndex = 0;
                this.tabela.Text = i.ToString ();
                this.tabela.UseVisualStyleBackColor = true;
                j = j + 1;
            }

            this.Controls.Add(tabControl2);

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0

Eu consegui vou postar o código se alguém precisar!

Segue:

tabela = new TabPage();
            tabela1 = new TabPage();
            tabControl2.SuspendLayout();
            this.SuspendLayout();
            int ano1 = 1996, ano2 = 1998;
            int result = ano2 - ano1;

            int j = 1;
            for (int i = ano1; i <= ano2; i++)
            {
           
                tabela = new TabPage();
               
                this.tabControl2.Location = new System.Drawing.Point(12, 12);
                this.tabControl2.Name = "tab";
                this.tabControl2.SelectedIndex = 0;
                this.tabControl2.Size = new System.Drawing.Size(268, 100);
                this.tabControl2.TabIndex = 0;

                this.tabela.Location = new System.Drawing.Point(4, 22);
                this.tabela.Name = "tabela" + j.ToString();

                this.tabela.Padding = new System.Windows.Forms.Padding(3);
                this.tabela.Size = new System.Drawing.Size(260, 74);
                this.tabela.TabIndex = 0;
                this.tabela.Text = i.ToString();
                this.tabela.UseVisualStyleBackColor = true;
                j = j + 1;
                this.tabControl2.Controls.Add(this.tabela);
                this.Controls.Add(tabControl2);

Editado por Adilson_web
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.


  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...