connectseekers.com

Tuesday, 9 September 2014

Dynamically Add textbox control on button click in windows application using C#.net and VB.net

9/09/2014 - By Pranav Singh 0

This article will show you  how you can add a testbox control one by one on button click and display it on groupbox in windows application using c#.net and vb.net. In this in each textbox I have added datetime as text.


So for this article first we will create a new windows application and add button and a group box control. After adding controls your form will look as shown below.




Now add the below code into your page.

C#.Net
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
    {
        public Form1()
        {
            InitializeComponent();
        }
        int xaxis = 0;
        int yaxis = 0;
        private void btnadd_Click(object sender, EventArgs e)
        {
            TextBox _objtextbox = new TextBox();
            _objtextbox.Text = DateTime.Now.ToString();
            _objtextbox.Width = 200;
            xaxis = 10;
            yaxis = yaxis + 30;
            _objtextbox.Location = new System.Drawing.Point(xaxis, yaxis);
            groupBox1.Controls.Add(_objtextbox);
        }
    }
}

VB.Net

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Namespace WindowsFormsApplication1
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub
        Private xaxis As Integer = 0
        Private yaxis As Integer = 0
        Private Sub btnadd_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim _objtextbox As New TextBox()
            _objtextbox.Text = DateTime.Now.ToString()
            _objtextbox.Width = 200
            xaxis = 10
            yaxis = yaxis + 30
            _objtextbox.Location = New System.Drawing.Point(xaxis, yaxis)
            groupBox1.Controls.Add(_objtextbox)
        End Sub
    End Class
End Namespace

Now we have done run the application.



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top