We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Background color of a XPToolBar item

Hi there,

Is there a way to set background color on a particular item inside a XPToolBar?
I have a button that I want to look different from the rest.

Thanks,
-Oleg.

4 Replies

MU Murugan Syncfusion Team May 22, 2007 09:28 PM UTC

Hi Oleg,

This could be achieved by handling the DrawToolbarItem event of the BarItem. Using this, we could draw background, image and String etc.

[Code]
this.barItem1.DrawToolbarItem += new DrawToolbarItemEventHandler (barItem1_DrawToolbarItem);

void barItem1_DrawToolbarItem(object sender, DrawToolbarItemEventArgs drawItemInfo)
{
Syncfusion.Windows.Forms.Tools.XPMenus.BarItem bi = (Syncfusion.Windows.Forms.Tools.XPMenus.BarItem)sender;
drawItemInfo.Graphics.FillRectangle(Brushes.Red, drawItemInfo.Bounds);
drawItemInfo.Graphics.DrawImage(bi.ImageList.Images[bi.ImageIndex],new Rectangle( drawItemInfo.Bounds.Location , new Size( drawItemInfo.Bounds.Size.Width , drawItemInfo.Bounds.Size.Height - 15 ) ) );
drawItemInfo.Graphics.DrawString(bi.Text , new Font("verdana", 7), new SolidBrush(Color.Green ), new PointF(drawItemInfo.Bounds.X, drawItemInfo.Bounds.Y + 22));
}

[Sample]
http://websamples.syncfusion.com/samples/Tools.Windows/F61266/Main.htm

Please refer to the sample and let me know if it helps you.

Thank you for your interest in Syncfusion products.

Regards,
Murugan P.S


OO Oleg Ogurok May 23, 2007 06:05 PM UTC

Thanks for your solution. It works. However, the hover effect is lost, e.g. when I position mouse pointer over the button, it doesn't get highlighted like the rest of the buttons.

Is there a way to preserve this effect?

-Oleg.


JA JayaLakshmi Syncfusion Team May 24, 2007 12:21 PM UTC

Hi Oleg,

Thanks for the update.

Just call a method DrawBackground()inside barItem1_DrawToolbarItem event handler to see the effect you want.

The code snippet is as follows :

drawItemInfo.DrawBackground();

Kindly let me know if this helps.

Regards,
Jaya


OO Oleg Ogurok May 25, 2007 01:04 PM UTC

Worked like a charm. Thank you very much.

Loader.
Live Chat Icon For mobile
Up arrow icon