Ticket T599091
Visible to All Users

Change background of the title bar in a XtraForm

created 7 years ago

Hi all,

I´m currently working with a XtraForm that will be the main container for my application. From this main form different XtraForms will raise.
What I want to achieve is to change the background colour of the Title Bar, but only for the Main Form.

I made a bit of researching in your KB and I followed an approach that consisted of overriding the OnShown method to change the corresponding the SkinElement. It worked fine for the Main Form but it was extended to the rest of forms, what I do not want to. The code snippet in the main form is:

C#
protected override void OnShown(EventArgs e) { base.OnShown(e); Skin currentSkin = FormSkins.GetSkin(this.LookAndFeel); SkinElement element = currentSkin[FormSkins.SkinFormCaption]; element.Image.Image = null; element.Color.BackColor = Color.FromArgb(194, 191, 184); this.LookAndFeel.UpdateStyleSettings(); }

I realised that changing the look & feel of the rest of the forms to not using the Skin provokes they do not have the new colour but we are losing the desired look & feel. So, how could I achieve this in a smarter way? I guess by a Custom Paint somewhere in the Main Form…?

Thanks,

Answers approved by DevExpress Support

created 7 years ago (modified 7 years ago)

Hi Eduardo,

You can accomplish this task by manually drawing the background. To do this, override the CreateFormBorderPainter method of your XtraForm:

C#
protected override FormPainter CreateFormBorderPainter() { return new MyFormPainter(this, DevExpress.LookAndFeel.UserLookAndFeel.Default.ActiveLookAndFeel); }

Create a FormPainter descendant and override the DrawBackground method. In this method, draw the background as you need:

C#
public class MyFormPainter : FormPainter { public MyFormPainter(Control owner, ISkinProvider provider) : base(owner, provider) { } protected override void DrawBackground(GraphicsCache cache) { //base.DrawBackground(cache); cache.FillRectangle(Color.FromArgb(194, 191, 184), CaptionBounds); } }

Please try this solution and let us know your results.

    Show previous comments (2)

      Hi all!
      After doing that, how can I change the XtraForm title text color?

      I tried with
      https://www.devexpress.com/Support/Center/Question/Details/T160334/how-to-change-title-bar-color-programmatically

      but its not working

      Thanks!

      DevExpress Support Team 6 years ago

        Thank you for keeping us posted. You are always welcome.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.