using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int counter = 0;
Label lbladd;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int offset = 0;
string prefix = "First";
Label lblShow = new Label();
lblShow.Name = prefix + offset.ToString();
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
this.Text = richTextBox1.Text.Length.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
lbladd = new Label();
lbladd.Text = "Hii";
counter++;
lbladd.Left = counter * 25;
lbladd.Width = 20;
lbladd.Height = 20;
lbladd.AutoSize = true;
lbladd.BackColor = Color.Beige;
lbladd.Name = "lbl" + counter.ToString();
panel1.Controls.Add(lbladd);
}
private void button2_Click(object sender, EventArgs e)
{
try
{
int a = 0;
foreach (Label lbl in panel1.Controls)
{
lbl.Text = a.ToString();
a++;
}
}
catch (NullReferenceException exc)
{
MessageBox.Show("No Control with the specufed name");
}
}
}
}