Hi,
I would like to control the font used by all of the controls in our application. Using a style file I have been able to set the base style role's fontName, this seems to work ok. I would rather not hard code the font name in the file and instead determine it at runtime and set this value accordingly. I could modify the style file prior to loading it if I have to but I was hoping for a better way. Should I muck with the StyleManager api to do this? I have found any examples of this.
Thanks for your help,
Bill
Hi Bill,
I think what you would have to load is load your StyleLibrary into memory and then modify the base UI Role in code.
But how you would do this depends on whether you want to load a library from a file first, or just create a new library. And do you want to save the changed setting to a file or just do all of this in code?
Hi Mike,
I would like to be able to do it all in code. Is it possible or do I need to load an isl file? Either way, can you show my how to modify the base UI in code?
Thanks again,
Well, this is kinda quick and crude, but the code would look something like this.
private void ultraFontNameEditor1_ValueChanged(object sender, EventArgs e) { ApplicationStyleLibrary styleLibrary = new ApplicationStyleLibrary(); styleLibrary.LoadFromStyleManager(); StyleSetSettings styleSet = null; if (styleLibrary.StyleSets.Count > 0 && styleLibrary.DefaultStyleSet != null) styleSet = styleLibrary.StyleSets[styleLibrary.DefaultStyleSet]; if (styleSet == null) { styleSet = styleLibrary.StyleSets.Add("Default"); styleLibrary.DefaultStyleSet = styleSet.Key; } StyleSettings baseRole = styleSet.RoleStyles.GetStyle("Base", true); StateSettings normalState = (baseRole.States.Exists(RoleState.Normal)) ? baseRole.States[RoleState.Normal] : baseRole.States.Add(RoleState.Normal); normalState.Appearance.FontData.Name = this.ultraFontNameEditor1.Text; styleLibrary.UpdateStyleManager(); }
I want to ask a related question in this thread.
I tried the above code in our application, and it works fine for all the controls, except one contol that is derived from UltraGrid.Inside this derived control, there does not seem to have anything related to Font change. It does not pick up the Font I set, but still use the default font.
Do you have any idea what could be the issue? Is there a way I can check whether the app style is set on the control?
Thanks.
I would think that a derived grid would pick up the application styling just as a normal grid does, unless something you are doing to the grid is overriding the appearance resolution somewhere.
Without knowing more about exactly what your derived grid is doing, though, it's hard to say.