Welcome to my website.This website has been designed with you in mind and will allow you to keep up-to-date with my work representing to you.........---Shashi---

Friday, 1 July 2011

Create Dyanamic Controls and Control Events..



Coding of this Form:

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        TextBox[] rch = new TextBox[3];
        int x = 0, y = 0;       
        public Form2()
        {
            InitializeComponent();
            for (int i = 0; i < rch.Length; i++)
            {
                rch[i] = new TextBox();
                rch[i].Width = 150;
                rch[i].Height = 150;
                rch[i].Name = "Textbox" + i;
                rch[i].Location = new Point(x, y);
                this.Controls.Add(rch[i]);
                y += 20;
            }
            rch[0].Enter += new EventHandler(ClickMe1);
            rch[1].Enter += new EventHandler(ClickMe2);
            rch[2].Enter += new EventHandler(ClickMe3);

            Button btn = new Button();
            btn.Width = 50; btn.Height = 30;
            btn.Name = "BtnName";
            btn.Text = "Zoom";
            btn.Location = new Point(113, 211);           
            this.Controls.Add(btn);
        }

        private void ClickMe1(object sender, EventArgs e)
        {
            MessageBox.Show("Its 1");
        }
        private void ClickMe2(object sender, EventArgs e)
        {
            MessageBox.Show("Its 2");
        }
        private void ClickMe3(object sender, EventArgs e)
        {
            MessageBox.Show("Its 3");
        }
    }
}

No comments:

Post a Comment