/// <summary>Sets the font set for the component passed.</summary> /// <param name="component">The component to set the font set for.</param> /// <param name="information">The name of the font set used.</param> protected void SetFontInformation(object component, FontSetInformation information) { if (FontSetInformation.Empty.Equals(information)) { if (ComponentToFontInformation.ContainsKey(component)) { //Reset the font. foreach (PropertyInfo property in component.GetType().GetProperties()) { if (property.CanRead && property.CanWrite && property.PropertyType == typeof(Font)) { property.SetValue(component, null, null); } } if (DesignMode) { //Remove the font set. ComponentToFontInformation.Remove(component); //Remove the type descriptor provider. TypeDescriptor.RemoveProvider(ComponentToTypeDescriptorProvider[component], component); ComponentToTypeDescriptorProvider.Remove(component); } } } else { ComponentToFontInformation[component] = information; Font fntFont = null; if (DesignMode || (Resolver == null)) { if (!ComponentToTypeDescriptorProvider.ContainsKey(component)) { ComponentToTypeDescriptorProvider[component] = new FontProviderTypeDescriptorProvider(component, TypeDescriptor.GetProvider(component)); TypeDescriptor.AddProvider(ComponentToTypeDescriptorProvider[component], component); } fntFont = new Font("Microsoft Sans Serif", information.Size, information.Style); } else { if (Resolver == null) { throw new Exception("The font set Resolver hasn't been assigned."); } fntFont = Resolver.RequestFont(information); } foreach (PropertyInfo property in component.GetType().GetProperties()) { if (property.CanRead && property.CanWrite && property.PropertyType == typeof(Font)) { property.SetValue(component, fntFont, null); } } } }
protected FontSetInformation GetFontInformation(object component) { if (ComponentToFontInformation.ContainsKey(component)) { return(ComponentToFontInformation[component]); } else { return(new FontSetInformation()); } }