TabPage.ImageIndex 属性
获取或设置在该选项卡上显示的图像的索引。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<LocalizableAttribute(True)> _
Public Property ImageIndex As Integer
用法
Dim instance As TabPage
Dim value As Integer
value = instance.ImageIndex
instance.ImageIndex = value
[LocalizableAttribute(true)]
public int ImageIndex { get; set; }
[LocalizableAttribute(true)]
public:
property int ImageIndex {
int get ();
void set (int value);
}
/** @property */
public int get_ImageIndex ()
/** @property */
public void set_ImageIndex (int value)
public function get ImageIndex () : int
public function set ImageIndex (value : int)
属性值
在选项卡上出现的 TabControl.ImageList 中的图像的从零开始的索引。默认值为 -1,表示没有图像。
异常
异常类型 | 条件 |
---|---|
ImageIndex 值小于 -1。 |
备注
ImageIndex 指向 TabControl 的关联 ImageList 中的图像。
示例
下面的代码示例创建一个包含一个 TabPage 的 TabControl。此示例使用 ImageIndex 属性来指定 myImages
的哪个图像将显示在 tabPage1
的选项卡上。
将 System.Drawing、System.ComponentModel、System.Windows.Forms 和 System.Resources 命名空间用于此示例。
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Resources
Public Class Form1
Inherits Form
Public Sub New()
Dim components = New Container()
Dim resources As New ResourceManager(GetType(Form1))
Dim tabControl1 As New TabControl()
Dim tabPage1 As New TabPage()
Dim myImages As New ImageList(components)
tabControl1.Controls.Add(tabPage1)
' Displays images from myImages on the tabs of tabControl1.
tabControl1.ImageList = myImages
' Specifies which image to display (on the tab of tabPage1) by its index.
tabPage1.ImageIndex = 0
tabPage1.Text = "tabPage1"
myImages.ImageStream = CType(resources.GetObject("myImages.ImageStream"), ImageListStreamer)
myImages.ColorDepth = ColorDepth.Depth8Bit
myImages.ImageSize = New Size(16, 16)
myImages.TransparentColor = Color.Transparent
Me.Controls.Add(tabControl1)
End Sub
Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Resources;
public class Form1 : Form
{
public Form1()
{
IContainer components = new Container();
ResourceManager resources = new ResourceManager(typeof(Form1));
TabControl tabControl1 = new TabControl();
TabPage tabPage1 = new TabPage();
ImageList myImages = new ImageList(components);
tabControl1.Controls.Add(tabPage1);
// Displays images from myImages on the tabs of tabControl1.
tabControl1.ImageList = myImages;
// Specifies which image to display (on the tab of tabPage1) by its index.
tabPage1.ImageIndex = 0;
tabPage1.Text = "tabPage1";
myImages.ImageStream = ((ImageListStreamer)(resources.GetObject("myImages.ImageStream")));
myImages.ColorDepth = ColorDepth.Depth8Bit;
myImages.ImageSize = new Size(16, 16);
myImages.TransparentColor = Color.Transparent;
this.Controls.Add(tabControl1);
}
static void Main()
{
Application.Run(new Form1());
}
}
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using namespace System::Resources;
public ref class Form1: public Form
{
public:
Form1()
{
IContainer^ components = gcnew System::ComponentModel::Container;
ResourceManager^ resources = gcnew ResourceManager( Form1::typeid );
TabControl^ tabControl1 = gcnew TabControl;
TabPage^ tabPage1 = gcnew TabPage;
ImageList^ myImages = gcnew ImageList( components );
tabControl1->Controls->Add( tabPage1 );
// Displays images from myImages on the tabs of tabControl1.
tabControl1->ImageList = myImages;
// Specifies which image to display (on the tab of tabPage1) by its index.
tabPage1->ImageIndex = 0;
tabPage1->Text = "tabPage1";
myImages->ImageStream = (dynamic_cast<ImageListStreamer^>(resources->GetObject( "myImages.ImageStream" )));
myImages->ColorDepth = ColorDepth::Depth8Bit;
myImages->ImageSize = System::Drawing::Size( 16, 16 );
myImages->TransparentColor = Color::Transparent;
this->Controls->Add( tabControl1 );
}
};
int main()
{
Application::Run( gcnew Form1 );
}
import System.Drawing.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
import System.Resources.*;
public class Form1 extends Form
{
public Form1()
{
IContainer components = new Container();
ResourceManager resources = new ResourceManager(Form1.class.ToType());
TabControl tabControl1 = new TabControl();
TabPage tabPage1 = new TabPage();
ImageList myImages = new ImageList(components);
tabControl1.get_Controls().Add(tabPage1);
// Displays images from myImages on the tabs of tabControl1.
tabControl1.set_ImageList(myImages);
// Specifies which image to display (on the tab of tabPage1) by its
// index.
tabPage1.set_ImageIndex(0);
tabPage1.set_Text("tabPage1");
myImages.set_ImageStream(((ImageListStreamer)(
resources.GetObject("myImages.ImageStream"))));
myImages.set_ColorDepth(ColorDepth.Depth8Bit);
myImages.set_ImageSize(new Size(16, 16));
myImages.set_TransparentColor(Color.get_Transparent());
this.get_Controls().Add(tabControl1);
} //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
请参见
参考
TabPage 类
TabPage 成员
System.Windows.Forms 命名空间
TabControl.ImageList 属性