This article will show you how you can dynamically textbox control
in a panel and clear all the controls on a single click using c#.net in windows
application.
Some of my previous articles are as follows: Confirmation
Message on Button Click and Capture YES/NO Click by User in Windows
application, C#, Error
Handling in Windows Application Using C#.Net, Restrict
User to Enter Only Negative, Non-Negative and Decimal Number in TextBox Using
C#.Net in Windows Application, Dynamically
Add textbox control on button click in windows application using C#.net and
VB.net, 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.
So for this article first we will create a new windows application and add a panel and button control.
Now add the code into the form.
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
count = 0;
int
top = 0;
private
void Form1_Load(object
sender, EventArgs e)
{
}
private
void button1_Click(object
sender, EventArgs e)
{
TextBox
objTextbox = new TextBox();
objTextbox.Name = "TextBox" + (count);
objTextbox.Text = "TextBox" + (count);
objTextbox.Top = top;
panel1.Controls.Add(objTextbox);
top += 20;
count += 1;
}
private
void button2_Click(object
sender, EventArgs e)
{
top = 0;
panel1.Controls.Clear();
}
}
}
|
In above code we have dynamically added
the textbox control and on clear button I have added code for clearing all the
controls.
DOWNLOAD
0 comments:
Please let me know your view