0 out of 1 rated this helpful - Rate this topic

ButtonBase.ImageKey Property

Gets or sets the key accessor for the image in the ImageList.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[TypeConverterAttribute(typeof(ImageKeyConverter))]
public string ImageKey { get; set; }

Property Value

Type: System.String
A string representing the key of the image.

The ImageKey property specifies the image from the image list to display on the control.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
You need to specify the Key when you add items to the ImageList

If you find this all a bit terse, what you probably need to know is that you specify the key when you add items to the ImageList.

For example...

' Add items to the ImageList specifying the key
Dim imgList as New ImageList()

imgList.Images.Add("tick", My.Resources.tick)

imgList.Images.Add("cross", My.Resources.cross)

imgList.Images.Add("blank", My.Resources.blank)

' Assign the ImageList to a CheckBox in this case

cboxReason.ImageList = imgList

' Then using this in a CheckBox event handler
Private Sub cboxReason_CheckStateChanged(sender As Object, e As System.EventArgs) Handles cboxReason.CheckStateChanged

Select Case cboxReason.CheckState

Case CheckState.Indeterminate

cboxReason.ImageKey = "blank"

Case CheckState.Unchecked

cboxReason.ImageKey = "cross"

Case CheckState.Checked

cboxReason.ImageKey = "tick"

End Select

End Sub