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.
Some of my previous articles are as follows: Paging
in DataGridview Using C#.Net In Windows Application, Show
Progressbar While Moving Folder File From One Directory To Other Using C#.Net
In Windows Application, Windows
Application - Excel Sheet Name in C#.Net.
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.
0 comments:
Please let me know your view