ToolStripItem.ImageKey Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur aksesor kunci untuk gambar dalam ImageList yang ditampilkan pada ToolStripItem.
public:
property System::String ^ ImageKey { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageKeyConverter))]
[System.Windows.Forms.RelatedImageList("Owner.ImageList")]
public string ImageKey { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ImageKeyConverter))>]
[<System.Windows.Forms.RelatedImageList("Owner.ImageList")>]
member this.ImageKey : string with get, set
Public Property ImageKey As String
Nilai Properti
String yang mewakili kunci gambar.
- Atribut
Contoh
Contoh kode berikut menunjukkan cara mengatur ImageKey properti. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ToolStripItem kelas .
// This utility method creates a RolloverItem
// and adds it to a ToolStrip control.
private RolloverItem CreateRolloverItem(
ToolStrip owningToolStrip,
string txt,
Font f,
string imgKey,
TextImageRelation tir,
string backImgKey)
{
RolloverItem item = new RolloverItem();
item.Alignment = ToolStripItemAlignment.Left;
item.AllowDrop = false;
item.AutoSize = true;
item.BackgroundImage = owningToolStrip.ImageList.Images[backImgKey];
item.BackgroundImageLayout = ImageLayout.Center;
item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;
item.DoubleClickEnabled = true;
item.Enabled = true;
item.Font = f;
// These assignments are equivalent. Each assigns an
// image from the owning toolstrip's image list.
item.ImageKey = imgKey;
//item.Image = owningToolStrip.ImageList.Images[infoIconKey];
//item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
item.ImageScaling = ToolStripItemImageScaling.None;
item.Owner = owningToolStrip;
item.Padding = new Padding(2);
item.Text = txt;
item.TextAlign = ContentAlignment.MiddleLeft;
item.TextDirection = ToolStripTextDirection.Horizontal;
item.TextImageRelation = tir;
return item;
}
' This utility method creates a RolloverItem
' and adds it to a ToolStrip control.
Private Function CreateRolloverItem( _
ByVal owningToolStrip As ToolStrip, _
ByVal txt As String, _
ByVal f As Font, _
ByVal imgKey As String, _
ByVal tir As TextImageRelation, _
ByVal backImgKey As String) As RolloverItem
Dim item As New RolloverItem()
item.Alignment = ToolStripItemAlignment.Left
item.AllowDrop = False
item.AutoSize = True
item.BackgroundImage = owningToolStrip.ImageList.Images(backImgKey)
item.BackgroundImageLayout = ImageLayout.Center
item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText
item.DoubleClickEnabled = True
item.Enabled = True
item.Font = f
' These assignments are equivalent. Each assigns an
' image from the owning toolstrip's image list.
item.ImageKey = imgKey
'item.Image = owningToolStrip.ImageList.Images[infoIconKey];
'item.ImageIndex = owningToolStrip.ImageList.Images.IndexOfKey(infoIconKey);
item.ImageScaling = ToolStripItemImageScaling.None
item.Owner = owningToolStrip
item.Padding = New Padding(2)
item.Text = txt
item.TextAlign = ContentAlignment.MiddleLeft
item.TextDirection = ToolStripTextDirection.Horizontal
item.TextImageRelation = tir
Return item
End Function
Keterangan
ImageKey dan ImageIndex saling eksklusif, yang berarti jika satu diatur, yang lain diatur ke nilai yang tidak valid dan diabaikan. Jika Anda mengatur ImageKey properti , ImageIndex properti secara otomatis diatur ke -1. Atau, jika Anda mengatur ImageIndex properti , ImageKey secara otomatis diatur ke string kosong ("").
Properti Image, , ImageIndexImageAlign, ImageKey, dan ImageScaling berkaitan dengan berbagai aspek penanganan gambar. Gunakan gambar dalam ToolStrip kontrol dengan mengatur properti ini secara langsung atau dengan mengatur properti run-time-only ImageList .
Penskalaan gambar ditentukan oleh interaksi properti di dan ToolStripToolStripItem, sebagai berikut:
ImageScalingSize adalah skala gambar akhir seperti yang ditentukan oleh kombinasi pengaturan gambar ImageScaling dan pengaturan kontainer AutoSize .
Jika AutoSize adalah
true(default) dan ToolStripItemImageScaling adalah SizeToFit, tidak ada penskalaan gambar yang terjadi, dan ToolStrip ukurannya adalah item terbesar, atau ukuran minimum yang ditentukan.Jika AutoSize dan adalah ToolStripItemImageScaling
falseNone, tidak ada gambar maupun ToolStrip penskalakan yang terjadi.