Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Control Tag Property

using System; using System.Drawing; using System.Windows.Forms; public class Tags : Form {   Label lbl;   public Tags()   {     Size = new Size(300,200);     lbl = new Label();     lbl.Text = "Label";     lbl.AutoSize = true;     lbl.Parent = this;     lbl.Location = new Point(0,0);     FontStyle theEnum = new FontStyle();     FontStyle[] theStyles = (FontStyle[])Enum.GetValues(theEnum.GetType());     int i = 1;     foreach (FontStyle style in theStyles)     {       Button btn = new Button();       btn.Parent = this;       btn.Location = new Point(25,25 * i++);       btn.Size = new Size(75,20);       btn.Text = style.ToString();       btn.Tag = style;       btn.Click += new System.EventHandler(btn_Click);     }   }   static void Main()    {     Application.Run(new Tags());   }   private void btn_Click(object sender, EventArgs e)   {     Button btn = (Button)sender;     FontStyle fs = (FontStyle)btn.Tag;     lbl.Font = new Font(lbl.Font, fs);   } }