Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações. |
Tradução
Original
|
Classe TabControl
Gerencia um conjunto relacionado de páginas de guia.
Assembly: System.Windows.Forms (em System.Windows.Forms.dll)
A TabControl contém páginas de guia, que são representadas por TabPage objetos adicionados por meio do TabPages propriedade. A ordem das páginas de guia nesta coleção reflete a ordem que as guias aparecem no controle.
O usuário pode alterar o corrente TabPage clicando em uma das guias no controle. Você pode alterar também programaticamente o corrente TabPage usando um dos seguintes TabControl propriedades:
In .NET Framework versão 2,0, você também pode usar um dos seguintes métodos:
In .NET Framework 2,0, você pode responder quando a guia corrente é alterado ao manipular um dos seguintes eventos:
Guias de um TabControl fazem parte do TabControl, mas não por partes do indivíduo TabPage controles. Membros a TabPage classe, sistema autônomo o ForeColor propriedade, afeta apenas o retângulo de cliente da página da guia, mas não sistema autônomo guias. Além disso, a Hide método para o TabPage não ocultará a guia. Para ocultar a guia, você deve remover o TabPage controlar a partir do TabControl.TabPages coleção.
In .NET Framework 2,0, na guia é considerada parte da página da guia para determinar quando o Enter e Leave eventos da TabPage ocorra. Em versões anteriores do .NET estrutura, a Enter e Leave eventos da TabPage não ocorrem quando o foco entra ou sai de uma guia, mas somente quando o foco entra ou deixa o retângulo de cliente da página da guia.
Os eventos a seguir não são disparados para o TabControl a menos que haja pelo menos um de classe TabPage no TabControl.TabPages coleção: Control.Click, Control.DoubleClick, Control.MouseDown, Control.MouseUp, Control.MouseHover, Control.MouseEnter, Control.MouseLeave e Control.MouseMove. Se houver pelo menos um TabPage na coleção, e o usuário interage com cabeçalho do controle guia (onde o TabPage nomes são exibidos), o TabControl aumenta o evento apropriado. No entanto, se a interação do usuário estiver dentro de ClientRectangle da página da guia, o TabPage aumenta o evento apropriado.
Controles contidos em um TabPage não serão criadas até a página da guia é mostrada e as ligações de dados nesses controles não serão ativadas até que a página da guia é exibida.
Quando os estilos visuais estão habilitados e o Alignment propriedade é conjunto com um valor diferente de Top, o Sumário da guia não pode ser renderizadas corretamente. Para contornar esse problema, você pode pintar na guia Sumário utilizando o desenho proprietário. Para obter mais informações, consulte Como: Exibir guias alinhadas lado com TabControl.
Quando o Alignment propriedade é conjunto com um valor diferente de Top e o Appearance propriedade é conjunto com um valor diferente de Normal, o Sumário da página da guia não pode ser renderizadas corretamente.
O exemplo de código a seguir usa o Visual Studio .NET Designer de Formulários do Windows para criar um TabControl com três páginas de guia. Cada página da guia contém vários controles.
publicclass Form1 : System.Windows.Forms.Form
{
// Required designer variable.private System.ComponentModel.Container components;
// Declare variables.private System.Windows.Forms.RadioButton tab3RadioButton2;
private System.Windows.Forms.RadioButton tab3RadioButton1;
private System.Windows.Forms.CheckBox tab2CheckBox3;
private System.Windows.Forms.CheckBox tab2CheckBox2;
private System.Windows.Forms.CheckBox tab2CheckBox1;
private System.Windows.Forms.Label tab1Label1;
private System.Windows.Forms.Button tab1Button1;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabControl tabControl1;
public Form1()
{
// This call is required for Windows Form Designer support.
InitializeComponent();
}
// This method is required for Designer support.privatevoid InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tab2CheckBox3 = new System.Windows.Forms.CheckBox();
this.tab3RadioButton2 = new System.Windows.Forms.RadioButton();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tab2CheckBox2 = new System.Windows.Forms.CheckBox();
this.tab2CheckBox1 = new System.Windows.Forms.CheckBox();
this.tab3RadioButton1 = new System.Windows.Forms.RadioButton();
this.tab1Label1 = new System.Windows.Forms.Label();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tab1Button1 = new System.Windows.Forms.Button();
tabPage1.Text = "tabPage1";
tabPage1.Size = new System.Drawing.Size(256, 214);
tabPage1.TabIndex = 0;
tab2CheckBox3.Location = new System.Drawing.Point(32, 136);
tab2CheckBox3.Text = "checkBox3";
tab2CheckBox3.Size = new System.Drawing.Size(176, 32);
tab2CheckBox3.TabIndex = 2;
tab2CheckBox3.Visible = true;
tab3RadioButton2.Location = new System.Drawing.Point(40, 72);
tab3RadioButton2.Text = "radioButton2";
tab3RadioButton2.Size = new System.Drawing.Size(152, 24);
tab3RadioButton2.TabIndex = 1;
tab3RadioButton2.Visible = true;
tabControl1.Location = new System.Drawing.Point(16, 16);
tabControl1.Size = new System.Drawing.Size(264, 240);
tabControl1.SelectedIndex = 0;
tabControl1.TabIndex = 0;
tab2CheckBox2.Location = new System.Drawing.Point(32, 80);
tab2CheckBox2.Text = "checkBox2";
tab2CheckBox2.Size = new System.Drawing.Size(176, 32);
tab2CheckBox2.TabIndex = 1;
tab2CheckBox2.Visible = true;
tab2CheckBox1.Location = new System.Drawing.Point(32, 24);
tab2CheckBox1.Text = "checkBox1";
tab2CheckBox1.Size = new System.Drawing.Size(176, 32);
tab2CheckBox1.TabIndex = 0;
tab3RadioButton1.Location = new System.Drawing.Point(40, 32);
tab3RadioButton1.Text = "radioButton1";
tab3RadioButton1.Size = new System.Drawing.Size(152, 24);
tab3RadioButton1.TabIndex = 0;
tab1Label1.Location = new System.Drawing.Point(16, 24);
tab1Label1.Text = "label1";
tab1Label1.Size = new System.Drawing.Size(224, 96);
tab1Label1.TabIndex = 1;
tabPage3.Text = "tabPage3";
tabPage3.Size = new System.Drawing.Size(256, 214);
tabPage3.TabIndex = 2;
tabPage2.Text = "tabPage2";
tabPage2.Size = new System.Drawing.Size(256, 214);
tabPage2.TabIndex = 1;
tab1Button1.Location = new System.Drawing.Point(88, 144);
tab1Button1.Size = new System.Drawing.Size(80, 40);
tab1Button1.TabIndex = 0;
tab1Button1.Text = "button1";
tab1Button1.Click += new
System.EventHandler(this.tab1Button1_Click);
this.Text = "Form1";
// Adds controls to the second tab page.
tabPage2.Controls.Add(this.tab2CheckBox3);
tabPage2.Controls.Add(this.tab2CheckBox2);
tabPage2.Controls.Add(this.tab2CheckBox1);
// Adds controls to the third tab page.
tabPage3.Controls.Add(this.tab3RadioButton2);
tabPage3.Controls.Add(this.tab3RadioButton1);
// Adds controls to the first tab page.
tabPage1.Controls.Add(this.tab1Label1);
tabPage1.Controls.Add(this.tab1Button1);
// Adds the TabControl to the form.this.Controls.Add(this.tabControl1);
// Adds the tab pages to the TabControl.
tabControl1.Controls.Add(this.tabPage1);
tabControl1.Controls.Add(this.tabPage2);
tabControl1.Controls.Add(this.tabPage3);
}
privatevoid tab1Button1_Click (object sender, System.EventArgs e)
{
// Inserts the code that should run when the button is clicked.
}
publicstaticvoid Main(string[] args)
{
Application.Run(new Form1());
}
}
public class Form1 extends System.Windows.Forms.Form
{
// Required designer variable.
private System.ComponentModel.Container components;
// Declare variables.
private System.Windows.Forms.RadioButton tab3RadioButton2;
private System.Windows.Forms.RadioButton tab3RadioButton1;
private System.Windows.Forms.CheckBox tab2CheckBox3;
private System.Windows.Forms.CheckBox tab2CheckBox2;
private System.Windows.Forms.CheckBox tab2CheckBox1;
private System.Windows.Forms.Label tab1Label1;
private System.Windows.Forms.Button tab1Button1;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabControl tabControl1;
public Form1()
{
// This call is required for Windows Form Designer support.
InitializeComponent();
} //Form1
// This method is required for Designer support.
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tab2CheckBox3 = new System.Windows.Forms.CheckBox();
this.tab3RadioButton2 = new System.Windows.Forms.RadioButton();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tab2CheckBox2 = new System.Windows.Forms.CheckBox();
this.tab2CheckBox1 = new System.Windows.Forms.CheckBox();
this.tab3RadioButton1 = new System.Windows.Forms.RadioButton();
this.tab1Label1 = new System.Windows.Forms.Label();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tab1Button1 = new System.Windows.Forms.Button();
tabPage1.set_Text("tabPage1");
tabPage1.set_Size(new System.Drawing.Size(256, 214));
tabPage1.set_TabIndex(0);
tab2CheckBox3.set_Location(new System.Drawing.Point(32, 136));
tab2CheckBox3.set_Text("checkBox3");
tab2CheckBox3.set_Size(new System.Drawing.Size(176, 32));
tab2CheckBox3.set_TabIndex(2);
tab2CheckBox3.set_Visible(true);
tab3RadioButton2.set_Location(new System.Drawing.Point(40, 72));
tab3RadioButton2.set_Text("radioButton2");
tab3RadioButton2.set_Size(new System.Drawing.Size(152, 24));
tab3RadioButton2.set_TabIndex(1);
tab3RadioButton2.set_Visible(true);
tabControl1.set_Location(new System.Drawing.Point(16, 16));
tabControl1.set_Size(new System.Drawing.Size(264, 240));
tabControl1.set_SelectedIndex(0);
tabControl1.set_TabIndex(0);
tab2CheckBox2.set_Location(new System.Drawing.Point(32, 80));
tab2CheckBox2.set_Text("checkBox2");
tab2CheckBox2.set_Size(new System.Drawing.Size(176, 32));
tab2CheckBox2.set_TabIndex(1);
tab2CheckBox2.set_Visible(true);
tab2CheckBox1.set_Location(new System.Drawing.Point(32, 24));
tab2CheckBox1.set_Text("checkBox1");
tab2CheckBox1.set_Size(new System.Drawing.Size(176, 32));
tab2CheckBox1.set_TabIndex(0);
tab3RadioButton1.set_Location(new System.Drawing.Point(40, 32));
tab3RadioButton1.set_Text("radioButton1");
tab3RadioButton1.set_Size(new System.Drawing.Size(152, 24));
tab3RadioButton1.set_TabIndex(0);
tab1Label1.set_Location(new System.Drawing.Point(16, 24));
tab1Label1.set_Text("label1");
tab1Label1.set_Size(new System.Drawing.Size(224, 96));
tab1Label1.set_TabIndex(1);
tabPage3.set_Text("tabPage3");
tabPage3.set_Size(new System.Drawing.Size(256, 214));
tabPage3.set_TabIndex(2);
tabPage2.set_Text("tabPage2");
tabPage2.set_Size(new System.Drawing.Size(256, 214));
tabPage2.set_TabIndex(1);
tab1Button1.set_Location(new System.Drawing.Point(88, 144));
tab1Button1.set_Size(new System.Drawing.Size(80, 40));
tab1Button1.set_TabIndex(0);
tab1Button1.set_Text("button1");
tab1Button1.add_Click(new System.EventHandler(this.tab1Button1_Click));
this.set_Text("Form1");
// Adds controls to the second tab page.
tabPage2.get_Controls().Add(this.tab2CheckBox3);
tabPage2.get_Controls().Add(this.tab2CheckBox2);
tabPage2.get_Controls().Add(this.tab2CheckBox1);
// Adds controls to the third tab page.
tabPage3.get_Controls().Add(this.tab3RadioButton2);
tabPage3.get_Controls().Add(this.tab3RadioButton1);
// Adds controls to the first tab page.
tabPage1.get_Controls().Add(this.tab1Label1);
tabPage1.get_Controls().Add(this.tab1Button1);
// Adds the TabControl to the form.
this.get_Controls().Add(this.tabControl1);
// Adds the tab pages to the TabControl.
tabControl1.get_Controls().Add(this.tabPage1);
tabControl1.get_Controls().Add(this.tabPage2);
tabControl1.get_Controls().Add(this.tabPage3);
} //InitializeComponent
private void tab1Button1_Click(Object sender, System.EventArgs e)
{
// Inserts the code that should run when the button is clicked.
} //tab1Button1_Click
public static void main(String[] args)
{
Application.Run(new Form1());
} //main
} //Form1
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.TabControl
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC
o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.