Click here to Skip to main content
15,891,513 members
Articles / Web Development / ASP.NET

FontInfo property for ASP.NET components

Rate me:
Please Sign up or sign in to vote.
3.18/5 (7 votes)
5 Dec 2005CPOL 33.1K   16   4
An article on how to create a FontInfo property for an ASP.NET component.

Introduction

During the development of some ASP.NET components, I experienced a bit of a trouble implementing the FontInfo property for ASP.NET components. First of all, I didn't find a public constructor for the FontInfo class. But there is a Style class which could be used to create a FontInfo instance.

C#
FontInfo  _myFont;
Style _style;
_style=new System.Web.UI.WebControls.Style();
_myFont =style.Font;

Another thing I've found is that the newly created FontInfo property is not serialized in the ASPX form like other properties. And every time I reopen the web form, at design time, the FontInfo property gets its default value = "". This problem was solved by adding the DesignerSerializationVisibility attribute:

C#
<Bindable(true),DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
     Category("Appearance"),
   Description ("My font property.")>
public FontInfo MyFont
{...}

Now the control on the web form serializes the information about the FontInfo property:

<cc1:mywebcontrol id="MyWebControl1" runat="server" 
        Height="50px" Width="450px"
        MyFont-Names="Century Gothic" MyFont-Italic="True" >
</cc1:mywebcontrol>

Hope that helps!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSerialization Pin
Squid.net29-Apr-07 19:40
Squid.net29-Apr-07 19:40 
GeneralThanks for the time saver. Pin
Squid.net29-Apr-07 18:41
Squid.net29-Apr-07 18:41 
GeneralGreat tip Pin
abhiace28-Feb-06 12:23
abhiace28-Feb-06 12:23 
GeneralRe: Great tip Pin
Peraxel11-Apr-07 23:21
Peraxel11-Apr-07 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.