我在下拉列表中有一個帶有各種元素的ToolStripSplitButton。 其中之一是放在ToolStripControlHost中的Trackbar,名爲ToolStripTrackbarItem。它的代碼(我從計算器了它):在下拉菜單中顯示ToolStripControlHost的圖像
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace Application
{
[System.ComponentModel.DesignerCategory("code")]
[System.Windows.Forms.Design.ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ContextMenuStrip | ToolStripItemDesignerAvailability.MenuStrip)]
public class ToolStripTrackbarItem : ToolStripControlHost
{
public ToolStripTrackbarItem()
: base(CreateControlInstance())
{
this.Size = Control.Size;
}
public TrackBar TrackBar
{
get { return Control as TrackBar; }
}
private static Control CreateControlInstance()
{
TrackBar t = new TrackBar();
t.AutoSize = false;
return t;
}
[DefaultValue(0)]
public int Value
{
get { return TrackBar.Value; }
set { TrackBar.Value = value; }
}
protected override void OnSubscribeControlEvents(Control control)
{
base.OnSubscribeControlEvents(control);
TrackBar trackBar = control as TrackBar;
trackBar.ValueChanged += new EventHandler(trackBar_ValueChanged);
}
protected override void OnUnsubscribeControlEvents(Control control)
{
base.OnUnsubscribeControlEvents(control);
TrackBar trackBar = control as TrackBar;
trackBar.ValueChanged -= new EventHandler(trackBar_ValueChanged);
}
void trackBar_ValueChanged(object sender, EventArgs e)
{
if (this.ValueChanged != null)
ValueChanged(sender, e);
}
public event EventHandler ValueChanged;
protected override Size DefaultSize
{
get { return new Size(300, 16); }
}
}
它的工作原理,但我需要顯示的圖像的下拉列表項的左:
我成功的一個簡單的ToolStripMenuItem通過設置Image屬性。但是,設置我的ToolStripTrackbarItem的Image屬性(從ToolStripControlHost繼承,請參閱上面的代碼)是無效的。根據MSDN,Image屬性與ToolStripControlHost無關。
這是什麼意思? ToolStripControlHost包含的圖像是否甚至不可能?
如果可能無論如何,該怎麼做?