asp.net.ph

WebControl.Font Property

System.Web.UI.WebControls Namespace   WebControl Class


Sets or retrieves the separate font attributes of a Web control.

Syntax


Inline <asp:control font-subproperty = strValue | true | false ... >
Script WebControl.Font.subproperty [ = strValue | true | false ]

Property Value

A FontInfo object that specifies the font information of the Web control.

Remarks

The Font property uses as sub-properties the properties of the FontInfo class. These sub-properties can be accessed declaratively in the form of Font-Subproperty or programmatically in the form of Font.Subproperty.

All but one sub-property, Overline, will render on downlevel browsers for all controls.

Example

The following example shows how to declaratively set the Font properties of a Web control at design time.

<asp:datagrid id = "myGrid" runat = "server"
   font-size = "9pt"
   font-bold=true />

The example below shows how to programmatically set and retrieve a Web control's Font properties at run time, depending on user input. The code also demonstrates how simple it is to retrieve the available system fonts and dynamically add each to a selectable list.

void Page_Load ( Object src, EventArgs e ) {
   if ( !IsPostBack ) {
      InstalledFontCollection installedFonts = new InstalledFontCollection ( );
      FontFamily [ ] fonts = installedFonts.Families;
      foreach ( FontFamily f in fonts ) {
         fontsSelect.Items.Add ( f.Name );
      }

      for ( int i=10; i<=20; i+=2 ) {
         sizeSelect.Items.Add ( i.ToString ( ) );
      }
      sizeSelect.SelectedIndex = 1;
   }
   greeting.Font.Name = fontsSelect.SelectedItem.Text;
   greeting.Font.Size = int.Parse ( sizeSelect.SelectedItem.Text );
   displayFontInfo ( );
}

void displayFontInfo ( ) {
   lblFontInfo.Text = greeting.Font.ToString ( );
   if ( cbBold.Checked ) lblFontInfo.Text += " Bold";
   if ( cbItalic.Checked ) lblFontInfo.Text += " Italic";
   if ( cbOverline.Checked ) lblFontInfo.Text += " Overline";
   if ( cbStrikeout.Checked ) lblFontInfo.Text += " Strikeout";
   if ( cbUnderline.Checked ) lblFontInfo.Text += " Underline";
}

void setFont ( Object src, EventArgs e ) {
   greeting.Font.Name = fontsSelect.SelectedItem.Value;
   greeting.Font.Size = int.Parse ( sizeSelect.SelectedItem.Text );
   greeting.Font.Bold = cbBold.Checked;
   greeting.Font.Italic = cbItalic.Checked;
   greeting.Font.Overline = cbOverline.Checked;
   greeting.Font.Strikeout = cbStrikeout.Checked;
   greeting.Font.Underline = cbUnderline.Checked;
}

 Show me 

See Also

WebControl Members   Style   FontInfo   Base Web Control Properties Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph