Programmatically Created ToolStrip Renders Incorrectly

6 posts, 1 answers
  1. Phillip
    Phillip avatar
    31 posts
    Member since:
    Apr 2009

    Posted 17 Apr 2009 Link to this post

    Hi,

    I programmatically create interfaces rather than use VS.net Designer, and almost all Telerik Windows Forms controls work Ok with this, however I cannot get the toolstrip to render correctly using the default application theme. If I switch default application themes having created and loaded my new toolstrip it renders correctly but until I toggle the theme it looks poor.

    I try to work around this by calling  the following for each control I create at runtime;

     

    private void applyThemeToGeneratedControl(Telerik.WinControls.RadControl control)

     

    {

    control.ThemeName = Telerik.WinControls.

    ThemeResolutionService.ApplicationThemeName;

     

    control.RootElement.ForceReApplyStyle();

    control.RootElement.ForceApplyTheme();

    }

    which does work for the majority of controls, but not for toolstrip.

    Any ideas what I'm doing wrong here ?

    Thanks,
    Phillip

  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 20 Apr 2009 Link to this post

    Hello Phillip,

    I'm not sure what could be the problem here. I have tested locally in our Demo application. The steps in my test scenario are:

    1. Drag and drop a new instance of RadButton
    2. Subscribe to button click event.
    3. Create a new RadToolStrip and add RadToolStripElement and RadToolStripItem to it, then modify its theme and change it to "Desert".

     private void radButton2_Click(object sender, EventArgs e)
            {
                RadToolStrip toolStrip = new RadToolStrip();
                toolStrip.Size = new Size(150, 30);

                RadToolStripElement toolStripElement = new RadToolStripElement();
                RadToolStripItem toolStripItem = new RadToolStripItem();
                toolStrip.Items.Add(toolStripElement);
                toolStripElement.Items.Add(toolStripItem);

                this.Controls.Add(toolStrip);


                toolStrip.ThemeName = "Desert";
            }

    The following code worked for me. Please make sure that the Theme component is added to the component tray when you change the theme. In my case I had to drag and drop the Desert Theme component.

    Please write me back if the information here has helped you. If not I will greatly appreciate if you send me a sample project demonstrating the issue and I will do my best to fix it.

    Kind regards,
    Boyko Markov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Phillip
    Phillip avatar
    31 posts
    Member since:
    Apr 2009

    Posted 20 Apr 2009 Link to this post

    Boyko,

    Thanks for the reply.

    I think my problem must be a misunderstanding of the way the theme in the component tray is handled. I had assumed that if I could address a named theme through the ApplicationThemeName, that meant it was loaded correctly (I had assumed an Exception if this theme had not been loaded or could not be deserialized at the time of naming it).

    I do have the named theme loaded as a component in the main application shell window, however it is not loaded in the specific container that I'm creating the tool strip into. My window structure is;

    MainWindow -> has Vista Theme Component loaded
    -- Tabs -> created at design time
    ---- Tab -> Created at runtime
    ------- Tool Strip -> Created at runtime. Doesn't seem to inherit the ApplicationThemeName that was set at design time.

    My assumption here is that the Setter of the ApplicationThemeName walks the application control tree and resets its applies the style and thematics, which is why I'm trying to forcible apply the ApplicationThemeName to the control once I've created it. If, afer creating my Tool Strip I toggle the value of the ApplicationThemeName then everything renders fine (following the neccessary pause).

    In the above structure, where would you expect to find a reference to the Theme component ? On the Form (its already there) or on some lower level control ?

    Thanks
    Phillip
  5. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 27 Apr 2009 Link to this post

    Hello Phillip,

    The purpose of the ApplicationThemeName property is to set the theme for all the controls in your application. However, ApplicationThemeName does not load themes. The themes are loaded in your application when you drag and drop a theme component on your form. The moment during the run-time where you set ApplicationThemeName does not matter - even if you create controls after you set ApplicationThemeName, they will know about this setting and they will have the correct theme applied (if this theme is loaded).

    I suppose that your issue is related to the Vista theme for RadToolStrip. Please note that in Q1 2009 RadToolStrip does not have a Vista theme in the Vista theme component. Therefore, even if you set ApplicationThemeName to Vista, you will not get the desired look. I am glad to inform you that we included Vista theme for RadToolStrip in the Vista theme component in Q1 2009 SP1 (v.2009.1.9.414). In order to update from Q1 2009 to Q1 2009 SP1, please refer to the following Knowledge Base article.

    I hope this helps. If you have additional questions, feel free to contact me.

    Best wishes,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Phillip
    Phillip avatar
    31 posts
    Member since:
    Apr 2009

    Posted 11 Aug 2009 Link to this post

    I eventually found out what the problem was. When placed in Design mode, all Telerik controls have a BeginInit() and EndInit() called on them. Most Windows Forms Controls don't. When dynamically creating Rad controls it is important to remember to include the BeginInit() and EndInit() calls otherwise visual artefacts will be produced.
  7. Answer
    Nick
    Admin
    Nick avatar
    767 posts

    Posted 18 Aug 2009 Link to this post

    Hello Phillip,

    Well, in most cases you do not need to call EndEdit, although there are certain places where it is obviously needed.

    Regards,
    Nick
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for WinForms is Visual Studio 2017 Ready