Click here to Skip to main content
Licence CPOL
First Posted 5 Dec 2005
Views 21,129
Bookmarked 16 times

FontInfo property for ASP.NET components

By | 5 Dec 2005 | Article
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.

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:

<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)

About the Author

Tadas Budvytis

Team Leader

Canada Canada

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSerialization PinmemberSquid.net19:40 29 Apr '07  
GeneralThanks for the time saver. PinmemberSquid.net18:41 29 Apr '07  
GeneralGreat tip Pinmemberabhiace12:23 28 Feb '06  
Great job!.
I was about to pull my hair out trying to figure out how to get the "Font" property to display and persist for a custom Web control in the designer view.
now all I do is the following:
 
[Bindable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Description("The font used for text within the control."),
Category("CalendarAppearance"),
DefaultValue("")]
public FontInfo Font
{
get
{
//mFont is declared as a private data member of type FontInfo
if(this.mFont == null)
{
Style s = new Style();
mFont = s.Font;
}
return mFont;
}
set
{
mFont= value;
}
}
 
And in the code for the control I pick up the value of mFont and set it on the webcontrol:
 
uxTextBox.Font = mFont
 
Smile | :)
 
-Abhijeet

GeneralRe: Great tip PinmemberPeraxel23:21 11 Apr '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 5 Dec 2005
Article Copyright 2005 by Tadas Budvytis
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid