共用方式為


TabPage.ImageIndex 屬性

定義

取得或設定顯示在這個索引標籤上的影像索引。

public:
 property int ImageIndex { int get(); void set(int value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))]
public int ImageIndex { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageIndexConverter))>]
member this.ImageIndex : int with get, set
Public Property ImageIndex As Integer

屬性值

Int32

中出現在索引標籤上之影像之 ImageList 以零起始的索引。預設值為 -1,表示沒有影像。

屬性

例外狀況

value 小於 -1。

範例

下列程式碼範例會使用一個 TabPageTabControl 建立 。 這個範例會 ImageIndex 使用 屬性,指定要在 myImages 索引 tabPage1 標籤上顯示哪些影像。

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 );
}
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());
    }
}
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

備註

指向 ImageIndex 相關聯 ImageList 之 中的 TabControl 影像。

ImageKeyImageIndex 互斥,這表示如果已設定,另一個設定為不正確值並忽略。 如果您設定 ImageKey 屬性, ImageIndex 則屬性會自動設定為 -1。 或者,如果您設定 ImageIndex 屬性,會自動 ImageKey 將 設定為空字串 (「」「) 。

適用於

另請參閱