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(); }
Thanks mike, that worked great...
Well, if you only want to do this for some controls, it will be tricky. I think you will either have to use a StyleSetName or StyleLibraryName so that those controls you want to adjust are using a different StyleSet or Library than the rest of the controls in the application. I don't see any easier way to do it.
I believe that would change the font size of all the controls application wide, I only want to do that on certain controls. What I would like to do is have a base font and size that all controls would use like Tahoma 8. This information will be user customizable. Under certain situations I want to relax the font size requirement on a control by control basis. So, I am looking for a way to tell a control to stop using the font size that is coming from appstylist and instead use the one i am providing.
Attached is an example of what I am doing. In the print screen the grids font size changes when the user moves the slider. The only way I came up with to handle this situation is to swap the styleset in and out on the grid like this:
{
}
else
where the "Zoom" style set is the same as the base style set without a font size setting
Thanks for any ideas,
Why not change the font size in the currently loaded style library?
I have a follow up question. I used the code you posted to set the default font name. I also updated it to set the font size as well which is causing some problems. This works great. We attach a zoom control to our grids and trees that allow the user to zoom in and out. To accomplish this we just change the font size. This no longer works because of the hardcoded font size in the style library. What is the best way to allow the changing of the font size during zoom, but still use the same font? I was thinking I could create 2 style sets one that is the base and another that is the zoom which is the base without a hard coded font size. During the zoom I would just switch over to the Zoom style set. Is there a better way to do this?
Thanks,