C# Code For Create Dynamic TextBox Label And Button In Dot NET


This is a C# Practice code:
    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;
    using System.Data;


    namespace ModelProjectForBlog
    {
        public partial class DynamicTXTBTLAB : Form
        {
            public DynamicTXTBTLAB()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)  //Code For TextBox
            {
                AddNewTextBox();
            }
            int A = 1;
            public System.Windows.Forms.TextBox AddNewTextBox()
            {
                System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
                this.Controls.Add(txt);
                txt.Top = A * 28;
                txt.Left = 10;
                txt.Text = "TextBox" + this.A.ToString();
                A = A + 1;
                txt.BackColor = Color.White;
                txt.ForeColor = Color.Black;
                txt.Font = new Font(txt.Font, FontStyle.Bold);  
                return txt;
            }

            private void button2_Click(object sender, EventArgs e)   //Code For Label
            {
                AddNewLabel();
            }
            int B = 1;
            public System.Windows.Forms.Label AddNewLabel()
            {
                System.Windows.Forms.Label abc = new System.Windows.Forms.Label();
                this.Controls.Add(abc);
                abc.Top = B * 28;
                abc.Left = 150;
                abc.Text = "Label" + this.B.ToString();
                B = B + 1;
                abc.BackColor = Color.Silver;
                abc.ForeColor = Color.Black;
                abc.Font = new Font(abc.Font, FontStyle.Bold);  
                return abc;
            }
            private void button3_Click(object sender, EventArgs e)    //Code For Button
            {
                AddNewButton();
            }
            int c = 1;
            public System.Windows.Forms.Button AddNewButton()
            {
                System.Windows.Forms.Button btn = new System.Windows.Forms.Button();
                this.Controls.Add(btn);
                btn.Top = c * 28;
                btn.Left = 290;
                btn.Text = "Label" + this.c.ToString();
                c = c + 1;
                btn.BackColor = Color.DarkGreen;
                btn.ForeColor = Color.White;
                btn.Font = new Font(btn.Font, FontStyle.Bold);  
                return btn;
            }
        
        }
    }
Video For Result:
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Facebook Comment