TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How To Add Multiple Textbox And Button At A Time In Window Form Application
Shreesh Raj
Jul 21
2016
Code
1.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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 {
int
ctextbox;
int
cbutton;
int
btntop = 1;
public
Form1() {
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e) {
try
{
ctextbox =
int
.Parse(textBox1.Text);
cbutton =
int
.Parse(textBox2.Text);
if
(textBox1.Text ==
""
&& textBox2.Text ==
""
) {
MessageBox.Show(
"Please enter your value first"
);
}
else
{
for
(
int
i = 0; i <=
int
.Parse((textBox1.Text)) - 1; i = i + 1) {
TextBox txt =
new
TextBox();
this
.Controls.Add(txt);
txt.Text =
"TextBox"
+ (i + 1);
txt.Top = btntop * 25;
txt.Left = 20;
txt.BackColor = Color.Red;
btntop = btntop + 1;
}
for
(
int
i = 0; i <=
int
.Parse((textBox2.Text)) - 1; i = i + 1) {
Button btn =
new
Button();
this
.Controls.Add(btn);
btn.Text =
"Button"
+ (i + 1);
btn.Top = btntop * 25;
btn.Left = 20;
btn.BackColor = Color.Purple;
btntop = btntop + 1;
}
}
}
catch
{
MessageBox.Show(
"Please enter valid number"
);
}
}
}
}
multiplet controls
.net
add
c#
window form