This is a migrated thread and some comments may be shown as answers.

Programmatically Created ToolStrip Renders Incorrectly

5 Answers 81 Views
Toolstrip (obsolete as of Q3 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Phillip
Top achievements
Rank 1
Phillip asked on 17 Apr 2009, 11:53 AM
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

5 Answers, 1 is accepted

Sort by
0
Boyko Markov
Telerik team
answered on 20 Apr 2009, 07:11 AM
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.
0
Phillip
Top achievements
Rank 1
answered on 20 Apr 2009, 08:55 AM
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
0
Nikolay
Telerik team
answered on 27 Apr 2009, 11:04 AM
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.
0
Phillip
Top achievements
Rank 1
answered on 11 Aug 2009, 01:20 PM
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.
0
Accepted
Nick
Telerik team
answered on 18 Aug 2009, 11:54 AM
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.
Tags
Toolstrip (obsolete as of Q3 2010)
Asked by
Phillip
Top achievements
Rank 1
Answers by
Boyko Markov
Telerik team
Phillip
Top achievements
Rank 1
Nikolay
Telerik team
Nick
Telerik team
Share this question
or