如果你是綁MenuItem
,那麼我已經找到了解決辦法是這樣的一個:
var dropDownButton = new ToolBarButton();
dropDownButton.ImageIndex = 0;
dropDownButton.Style = ToolBarButtonStyle.DropDownButton;
var mniZero = new MenuItem("Zero", (o, e) => DoZero());
mniZero.OwnerDraw = true;
mniZero.DrawItem += delegate(object sender, DrawItemEventArgs e) {
double factor = (double) e.Bounds.Height/zeroIconBmp.Height;
var rect = new Rectangle(e.Bounds.X, e.Bounds.Y,
(int) (zeroIconBmp.Width * factor),
(int) (zeroIconBmp.Height * factor));
e.Graphics.DrawImage(zeroIconBmp, rect);
};
var mniOne = new MenuItem("One", (o, e) => DoOne());
mniOne.OwnerDraw = true;
mniOne.DrawItem += delegate(object sender, DrawItemEventArgs e) {
double factor = (double) e.Bounds.Height/oneIconBmp.Height;
var rect = new Rectangle(e.Bounds.X, e.Bounds.Y,
(int) (oneIconBmp.Width * factor),
(int) (oneIconBmp.Height * factor));
e.Graphics.DrawImage(oneIconBmp, rect);
};
dropDownButton.DropDownMenu = new ContextMenu(new MenuItem[]{
mniZero, mniOne,
});
希望這有助於。
你可以用'ContextMenuStrip'和'ToolStripMenuItem'來代替嗎?在這種情況下,您可以設置'ToolStripMenuItem.Image'。 http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx – Bolu