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;               //  Niezbdne dla FontFamily.
using System.Drawing.Text;          //  Niezbdne dla Fonts.

public partial class _Default : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      string str = "Pchn w t d jea lub om skrzy fig."; // Pangram .
      int i = 0;

      // Pobieramy styl przyciskw opcji.
      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;
            }
         }
      }

      //  Pobieramy rozmiar czcionki.
      int size = Convert.ToInt32(rblSize.SelectedItem.Value);

      //  Pobieramy list wszystkich czcionek zainstalowanych w systemie.
      //  Wypeniamy tabel czcionkami oraz przykadowym tekstem.
      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;

         // ID nie jest tutaj niezbdny.
         // Po prostu pokazujemy, e moe zosta ustawiony.
         i++;
         lbl.ID = "lbl" + i.ToString();

         // Ustawiamy nazw czcionki.
         lbl.Font.Name = ff.Name;

         // Ustawiamy styl czcionki.
         if (boolUnder)
            lbl.Font.Underline = true;
         if (boolOver)
            lbl.Font.Overline = true;
         if (boolStrike)
            lbl.Font.Strikeout = true;

         // Ustawiamy rozmiar czcionki.
         lbl.Font.Size = size;

         cText.Controls.Add(lbl);
         r.Cells.Add(cText);

         tbl.Rows.Add(r);
      }
   }

   protected void  cblFontStyle_Init(object sender, EventArgs e)
   {
      // Tworzymy tablice elementw do dodania.
      string[] FontStyle = {"Podkrelenie","Nakrelenie", "Przekrelenie"};
      string[] Code = {"u","o","s"};

      for (int i = 0; i < FontStyle.GetLength(0); i++)
      {
         // Dodajemy zarwno waciwoci Text, jak i Value.
         this.cblFontStyle.Items.Add(new ListItem(FontStyle[i],Code[i]));
      }
   }
}
