RadTitleBar with office2007black theme

5 posts, 0 answers
  1. mdanh
    mdanh avatar
    17 posts
    Member since:
    Jul 2012

    Posted 08 Jan 2010 Link to this post

    I am applying Office2007Black theme to RadTitleBar. I notice the title bar text is left/vertically aligned. How do I change the alignment to top-left. I have tried the Visual Styte Builder and change various alignment properties of RadTitleBar with no visible effects. What is the correct property to set?

    Thanks
  2. Deyan
    Admin
    Deyan avatar
    2038 posts

    Posted 12 Jan 2010 Link to this post

    Hi mdanh, 

    Thank you for contacting us and for your interest in RadControls for WinForms.

    I am not quite sure that I correctly understand the way you would like to align the text of the RadTitleBar control. However, I have prepared a screeshot which should demonstrate how you can use the Alignment property of the TextPrimitive which displays the text in this control.

    You should simply put a RadTitleBar control onto your form and open the Edit UI Elements dialog by using the Smart Tag of the control. In this dialog you should select the text primitive from the element hierarchy of the RadTitleBar and adjust its Alignment property by using the property grid on the right of the form.

    Please, refer to the screenshot for further details.

    I hope this is helpful. You can write back anytime you need further assistance.

    Best wishes,
    Deyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. mdanh
    mdanh avatar
    17 posts
    Member since:
    Jul 2012

    Posted 12 Jan 2010 Link to this post

    Thanks for the suggestion. I notice some effects after I changed the Alignment property you mentioned.

    However, even if I changed the alignment to BottomRight, the text is still on the bottom left. Is it because the Title text has a maximum width preventing if from being displayed on the right?

    Also what is the difference between changing the properties in Edit UI Elements and in the Visual Style Builder? If a property (Alignment, Forecolor, etc) appears in difference places (Visual Studio property grid, Edit UI Elements property grid and Visual Style Builder), which one will be applied if I set conflicting values for these properties? Lastly I noticed sometimes my changes are reflected correctly in the Visual Studio designer but has no effects when I run the program, any ideas why?

    Thanks.
  5. Deyan
    Admin
    Deyan avatar
    2038 posts

    Posted 18 Jan 2010 Link to this post

    Hello mdanh,

    Thanks for writing us back. Our controls are built upon Telerik Presentation Framework which provides a flexible property system that traces the value sources. In other words, you can easily determine whether a property value is set by code, by style, by animation, or this is the default value. Possible value sources have their precedence when the property value is composed. For example, if you have a property setting defined in a stylesheet (theme), it will override the default value for that property. Local values (those set by code) override the style values. Local values are respectively overriden by animation ones.


    When you modify properties in Visual Style Builder and save them in a stylesheet (theme), these values are later applied and the corresponding property value sources are marked as 'Style'. However, if you use Edit UI Elements dialog in Visual Studio Designer, these property values are applied as Local and as I mentioned above these values override the values that come from the stylesheet.

    In general, by setting the Alignment property of the TextPrimitive used in RadTitleBar, you will override the style settings, and thus, the text will be aligned correspondingly. However, the current implementation of the titlebar layout does not allow for such alignment which is incorrect (we will consider changing this in a future release).

    Please use the following work-around for the time being:

    public Form1()
    {
          InitializeComponent();
          TextPrimitive primitive = this.radTitleBar1.TitleBarElement.Children[2].Children[1] as TextPrimitive;
          primitive.Alignment = ContentAlignment.MiddleRight;
          primitive.Margin = Padding.Empty;
    }
      
    protected override void OnResize(EventArgs e)
    {
         base.OnResize(e);
         this.AdjustTextPrimitiveMinSize();
    }
      
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
      
        this.AdjustTextPrimitiveMinSize();
    }
      
    private void AdjustTextPrimitiveMinSize()
    {
          TextPrimitive primitive = this.radTitleBar1.TitleBarElement.Children[2].Children[1] as TextPrimitive;
          ImagePrimitive imagePrimitive = this.radTitleBar1.TitleBarElement.Children[2].Children[0] as ImagePrimitive;
          StackLayoutPanel stackLayout = this.radTitleBar1.TitleBarElement.Children[2].Children[2] as StackLayoutPanel;
          primitive.MinSize = new Size(stackLayout.ControlBoundingRectangle.X - imagePrimitive.ControlBoundingRectangle.Right, 0);
    }

    In general, the reason that the alignment does not work as expected is that the text is measured and its alignment space is calculated to be the exact size of the text. Thus, when you set the Alignment property, the text is aligned in a box which basically wraps the text.

    In this workaround I simply calculate the available space for the text and use the width of this space to set the MinSize property of the text. In this way, when you set the TextPrimitive Alignment property, it will be aligned as expected.

    I hope this helps. You can write back anytime you need further assistance.

    Greetings,
    Deyan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. mdanh
    mdanh avatar
    17 posts
    Member since:
    Jul 2012

    Posted 20 Jan 2010 Link to this post

    Thanks for your detailed reply.

    Your code works well and helps me align the form title text on the right. Thanks again :)
Back to Top
UI for WinForms is Visual Studio 2017 Ready