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

DrawBackground event in Bar class

Hi, What exactly is the DrawBackground event in the XPMenus.Bar class? I would think that it would allow one to override the drawing for the background of the bar, but my code doesn''t seem to be working. I have the following: private void barToolbar_DrawBackground(object sender, PaintEventArgs e) { Graphics g = e.Graphics; using (Brush b = new LinearGradientBrush(e.ClipRectangle, Color.Black,Color.White,LinearGradientMode.Horizontal)) { g.FillRectangle(b,e.ClipRectangle); } } Any idea as to what I''m doing wrong? If this is not correct, then is there some way to achieve custom drawing of the background? I''m going for a gradient background such as the one found in MS Word w/ XP themes turned on. Thanks for your help. - Jarrod

2 Replies

AD Administrator Syncfusion Team September 10, 2004 09:53 PM UTC

Hi Jarrod, Like the name suggests the DrawBackground event is used to paint the background of the Bar. But the XPMenus framework internally uses the CommandBars framework, and this factor has to be considered as well. The painting routines of the associated CommandBarExt and its BarControl occur after the Bar''s painting routine resulting in overwriting of the Bar''s custom painting. Hence the custom painting should be performed in the CommandBarExt.BarControl''s Paint event handler as well as shown in the code below : this.bar1.DrawBackground += new PaintEventHandler(bar1_DrawBackground); cmdbarext = this.mainFrameBarManager1.GetBarControl(this.bar1) as CommandBarExt; cmdbarext.BarControl.Paint += new PaintEventHandler(BarControl_Paint); private void bar1_DrawBackground(object sender, PaintEventArgs args) { // The CommandBarExt.BarControl''s painting takes place after the CommandBarExt is painted // Hence the custom painting should be done in the CommandBarExt.BarControl''s painting routine as well LinearGradientBrush brush = new LinearGradientBrush(cmdbarext.Bounds, Color.Yellow, Color.Red, 60, true); args.Graphics.FillRectangle(brush, cmdbarext.Bounds.X, cmdbarext.Bounds.Y, cmdbarext.Width, cmdbarext.Height); } private void BarControl_Paint (object sender, PaintEventArgs e) { LinearGradientBrush brush = new LinearGradientBrush(cmdbarext.Bounds, Color.Yellow, Color.Red, 60, true); e.Graphics.FillRectangle(brush, cmdbarext.Bounds.X, cmdbarext.Bounds.Y, cmdbarext.Width, cmdbarext.Height); } The complete sample illustrating this is attached here. Please refer to it and let me know if this meets your requirements. We appreciate your interest in Syncfusion products. Regards, Guru Patwal Syncfusion, Inc.

JP Jarrod Peace September 13, 2004 01:20 PM UTC

Hi Guru, That''s perfect. Thanks a lot for your help - Jarrod

Live Chat Icon For mobile
Up arrow icon