| |||||
WebControl.Font PropertySystem.Web.UI.WebControls Namespace WebControl Class Sets or retrieves the separate font attributes of a Web control. Syntax
Property ValueA FontInfo object that specifies the font information of the Web control. RemarksThe 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. ExampleThe 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;
}
See AlsoWebControl Members Style FontInfo Base Web Control Properties |
| ||||
Check out related books at Amazon
© 2000-2008 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 aspxtreme