All pastes #80917 Raw Edit

AJ

public text v1 · immutable
·published 2006-07-06 23:05 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        private Dictionary<string, TextBox> oc_DynamicTextBoxes = new Dictionary<string, TextBox>();
        private int i_Count = 1;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //AJ: create TB
            TextBox dynamicTextBox = new TextBox();
            //AJ: add TB to form and position and crap
            //AJ: and other setting up of crap goes here

            //AJ: set the name
            dynamicTextBox.Name = "TB" + this.i_Count;

            //AJ: add to the collection in this case using the TB name as its key
            this.oc_DynamicTextBoxes.Add(dynamicTextBox.Name, dynamicTextBox);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //AJ: make sure it exists
            if (this.oc_DynamicTextBoxes.ContainsKey("TB2"))
            {
                //AJ: diasble the TB as an example
                this.oc_DynamicTextBoxes["TB2"].Enabled = false;
            }
        }
    }
}