TabPage::ImageIndex Property

 

Gets or sets the index to the image displayed on this tab.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
[TypeConverterAttribute((ImageIndexConverter^::typeid))]
property int ImageIndex {
	int get();
	void set(int value);
}

Property Value

Type: System::Int32

The zero-based index to the image in the TabControl::ImageList that appears on the tab. The default is -1, which signifies no image.

Exception Condition
ArgumentException

The ImageIndex value is less than -1.

The ImageIndex points to an image in the associated ImageList of the TabControl.

The following code example creates a TabControl with one TabPage. This example uses the ImageIndex property to specify which image from myImages displays on the tab of tabPage1.

Use the System.Drawing, System.ComponentModel, System.Windows.Forms, and System.Resources namespace for this example.

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

.NET Framework
Available since 1.1
Return to top
Show: