<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default_aspx" %>
Table Control
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing; // necessary for FontFamily
using System.Drawing.Text; // necessary for Fonts
public partial class Default_aspx : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string str = "The quick brown fox jumped over the lazy dogs.";
int i = 0;
bool boolUnder = false;
bool boolOver = false;
bool boolStrike = false;
foreach(ListItem li in cblFontStyle.Items)
{
if (li.Selected == true)
{
switch (li.Value)
{
case "u":
boolUnder = true;
break;
case "o":
boolOver = true;
break;
case "s":
boolStrike = true;
break;
}
}
}
int size = Convert.ToInt32(rblSize.SelectedItem.Value);
InstalledFontCollection ifc = new InstalledFontCollection( );
foreach( FontFamily ff in ifc.Families )
{
TableRow r = new TableRow( );
TableCell cFont = new TableCell( );
cFont.Controls.Add(new LiteralControl(ff.Name));
r.Cells.Add(cFont);
TableCell cText = new TableCell( );
Label lbl = new Label( );
lbl.Text = str;
i++;
lbl.ID = "lbl" + i.ToString( );
lbl.Font.Name = ff.Name;
if (boolUnder)
lbl.Font.Underline = true;
if (boolOver)
lbl.Font.Overline = true;
if (boolStrike)
lbl.Font.Strikeout = true;
lbl.Font.Size = size;
cText.Controls.Add(lbl);
r.Cells.Add(cText);
tbl.Rows.Add(r);
}
}
protected void cblFontStyle_Init(object sender, EventArgs e)
{
string[] FontStyle = {"Underline","OverLine", "Strikeout"};
string[] Code = {"u","o","s"};
for (int i = 0; i < FontStyle.GetLength(0); i++)
{
this.cblFontStyle.Items.Add(new ListItem(FontStyle[i],Code[i]));
}
}
}