TabControl.Alignment 属性
获取或设置选项卡在其中对齐的控件区域(例如,顶部边缘)。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<LocalizableAttribute(True)> _
Public Property Alignment As TabAlignment
用法
Dim instance As TabControl
Dim value As TabAlignment
value = instance.Alignment
instance.Alignment = value
[LocalizableAttribute(true)]
public TabAlignment Alignment { get; set; }
[LocalizableAttribute(true)]
public:
property TabAlignment Alignment {
TabAlignment get ();
void set (TabAlignment value);
}
/** @property */
public TabAlignment get_Alignment ()
/** @property */
public void set_Alignment (TabAlignment value)
public function get Alignment () : TabAlignment
public function set Alignment (value : TabAlignment)
属性值
TabAlignment 值之一。默认为 Top。
异常
异常类型 | 条件 |
---|---|
属性值不是有效的 TabAlignment 值。 |
备注
当将 Alignment 属性设置为 Left 或 Right 时,自动将 Multiline 属性设置为 true。
如果将 Appearance 属性设置为 FlatButtons,它仅在 Alignment 属性设置为 Top 时才那样显示。否则,Appearance 属性如同设置为 Buttons 值一样显示。
将 Appearance 属性设置为 Buttons 时,还必须将 Alignment 属性设置为 Top,以使按钮正确显示。
提示
启用视觉样式并将 Alignment 属性设置为 Top 以外的值时,这些选项卡不能正确呈现。
示例
下面的代码示例创建一个包含三个 TabPage 对象的 TabControl。Alignment 属性设置为 Left,此设置将 tabControl1
的选项卡放置在左侧。
在此示例中使用 System.Drawing 和 System.Windows.Forms 命名空间。
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits Form
Private tabControl1 As TabControl
Private tabPage1 As TabPage
Private tabPage2 As TabPage
Private tabPage3 As TabPage
Private Sub MyTabs()
Me.tabControl1 = New TabControl()
Me.tabPage1 = New TabPage()
Me.tabPage2 = New TabPage()
Me.tabPage3 = New TabPage()
' Positions tabs on the left side of tabControl1.
Me.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Left
Me.tabControl1.Controls.AddRange(New Control() {Me.tabPage1, Me.tabPage2, Me.tabPage3})
Me.tabControl1.Location = New Point(16, 24)
Me.tabControl1.SelectedIndex = 0
Me.tabControl1.Size = New Size(248, 232)
Me.tabControl1.TabIndex = 0
Me.tabPage1.TabIndex = 0
Me.tabPage2.TabIndex = 1
Me.tabPage3.TabIndex = 2
Me.Size = New Size(300, 300)
Me.Controls.AddRange(New Control() {Me.tabControl1})
End Sub
Public Sub New()
MyTabs()
End Sub
Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class
using System.Drawing;
using System.Windows.Forms;
public class Form1 : Form
{
private TabControl tabControl1;
private TabPage tabPage1;
private TabPage tabPage2;
private TabPage tabPage3;
private void MyTabs()
{
this.tabControl1 = new TabControl();
this.tabPage1 = new TabPage();
this.tabPage2 = new TabPage();
this.tabPage3 = new TabPage();
// Positions tabs on the left side of tabControl1.
this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Left;
this.tabControl1.Controls.AddRange(new Control[] {
this.tabPage1,
this.tabPage2,
this.tabPage3});
this.tabControl1.Location = new Point(16, 24);
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new Size(248, 232);
this.tabControl1.TabIndex = 0;
this.tabPage1.TabIndex = 0;
this.tabPage2.TabIndex = 1;
this.tabPage3.TabIndex = 2;
this.Size = new Size(300,300);
this.Controls.AddRange(new Control[] {
this.tabControl1});
}
public Form1()
{
MyTabs();
}
static void Main()
{
Application.Run(new Form1());
}
}
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Form1: public Form
{
private:
TabControl^ tabControl1;
TabPage^ tabPage1;
TabPage^ tabPage2;
TabPage^ tabPage3;
void MyTabs()
{
this->tabControl1 = gcnew TabControl;
this->tabPage1 = gcnew TabPage;
this->tabPage2 = gcnew TabPage;
this->tabPage3 = gcnew TabPage;
// Positions tabs on the left side of tabControl1.
this->tabControl1->Alignment = System::Windows::Forms::TabAlignment::Left;
array<Control^>^tabControls = {this->tabPage1,this->tabPage2,this->tabPage3};
this->tabControl1->Controls->AddRange( tabControls );
this->tabControl1->Location = Point(16,24);
this->tabControl1->SelectedIndex = 0;
this->tabControl1->Size = System::Drawing::Size( 248, 232 );
this->tabControl1->TabIndex = 0;
this->tabPage1->TabIndex = 0;
this->tabPage2->TabIndex = 1;
this->tabPage3->TabIndex = 2;
this->Size = System::Drawing::Size( 300, 300 );
array<Control^>^formControls = {this->tabControl1};
this->Controls->AddRange( formControls );
}
public:
Form1()
{
MyTabs();
}
};
int main()
{
Application::Run( gcnew Form1 );
}
import System.Drawing.*;
import System.Windows.Forms.*;
public class Form1 extends Form
{
private TabControl tabControl1;
private TabPage tabPage1;
private TabPage tabPage2;
private TabPage tabPage3;
private void MyTabs()
{
this.tabControl1 = new TabControl();
this.tabPage1 = new TabPage();
this.tabPage2 = new TabPage();
this.tabPage3 = new TabPage();
// Positions tabs on the left side of tabControl1.
this.tabControl1.set_Alignment(System.Windows.Forms.TabAlignment.Left);
this.tabControl1.get_Controls().AddRange(new Control[] {
this.tabPage1, this.tabPage2, this.tabPage3 });
this.tabControl1.set_Location(new Point(16, 24));
this.tabControl1.set_SelectedIndex(0);
this.tabControl1.set_Size(new Size(248, 232));
this.tabControl1.set_TabIndex(0);
this.tabPage1.set_TabIndex(0);
this.tabPage2.set_TabIndex(1);
this.tabPage3.set_TabIndex(2);
this.set_Size(new Size(300, 300));
this.get_Controls().AddRange(new Control[] { this.tabControl1 });
} //MyTabs
public Form1()
{
MyTabs();
} //Form1
public static void main(String[] args)
{
Application.Run(new Form1());
} //main
} //Form1
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
TabControl 类
TabControl 成员
System.Windows.Forms 命名空间
Appearance
Multiline
TabAlignment 枚举