この記事は翻訳者によって翻訳されたものです。 記事の文章にポインターを重ねると、原文のテキストが表示されます。 |
訳文
原文
|
ButtonBase.ImageIndex プロパティ
ボタン コントロールに表示されているイメージのイメージ リスト内でのインデックス値を取得または設定します。
アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)
| 例外 | 条件 |
|---|---|
| ArgumentOutOfRangeException |
代入された値が ImageIndex の下限値より小さいです。 |
ImageIndex プロパティまたは ImageList プロパティが設定されている場合は、Image プロパティが既定値の null に設定されます。
メモ
|
|---|
|
ImageList プロパティの値が null に変更されると、ImageIndex プロパティはその既定値である -1 を返します。 ただし、割り当てられた ImageIndex 値は内部的に保持され、別の ImageList オブジェクトが ImageList プロパティに割り当てられているときに使用されます。 ImageList プロパティに割り当てられた新しい ImageList の ImageList.ImageCollection.Count プロパティ値が、ImageIndex プロパティに代入されている値から 1 を引いた値以下の場合 (コレクションが 0 から始まるインデックス番号であることを考慮)、ImageIndex プロパティ値は Count プロパティ値より 1 小さい値に調整されます。 たとえば、ImageList に 3 つのイメージがあり、ImageIndex プロパティが 2 に設定されているボタン コントロールがあるとします。 イメージが 2 つしかない新しい ImageList にボタンが割り当てられている場合、ImageIndex 値は 1 に変更されます。 |
派生クラス Button を使用して、ImageList プロパティと ImageIndex プロパティを設定するコード例を次に示します。 このコードでは、ImageList が作成されており、そこに Image が 1 つ以上割り当てられている必要があります。 また、C:\Graphics ディレクトリに MyBitMap.bmp という名前のビットマップ イメージが格納されている必要もあります。
private void AddMyImage() { // Assign an image to the ImageList. ImageList1.Images.Add(Image.FromFile("C:\\Graphics\\MyBitmap.bmp")); // Assign the ImageList to the button control. button1.ImageList = ImageList1; // Select the image from the ImageList (using the ImageIndex property). button1.ImageIndex = 0; }
Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2
.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
メモ