Friday, August 1, 2014

ToolStripControlHost 's image dose not show

i used ToolStripControlHost . but it 's image dose not show.



public class ContexMenuStrip2 : ContextMenuStrip
{


protected override void OnPaint(PaintEventArgs e)
{
for (int i = 0; i < this.Items.Count; i++)
{

try
{
if ((this.Items[i].Image != null) && (this.Items[i].GetType().BaseType == typeof(System.Windows.Forms.ToolStripControlHost)))
{
float x = 150;
float y = this.Items[i].Bounds.Y + ((this.Items[i].Bounds.Height / 2) - 20);
e.Graphics.DrawImage(Items[i].Image, x, y);
}
}
catch { }
}
base.OnPaint(e);
}
}

private void Form1_Load(object sender, EventArgs e)
{

ContexMenuStrip2 Menu = new ContexMenuStrip2();


Button btn = new Button();
btn.BackColor = Color.Pink;


ToolStripControlHost backcolorItem = new ToolStripControlHost(btn);
backcolorItem.BackgroundImageLayout = ImageLayout.None;
backcolorItem.Image = Image.FromFile(Application.StartupPath + "\\30.png");
backcolorItem.Width = 120;


backcolorItem.Name = "BgColor";
Menu.Items.Add(backcolorItem);


this.ContextMenuStrip = Menu;
}

i want s.th like this :



but it is like below now :




No comments:

Post a Comment