Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 117,570 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,791 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



creating textbox at run time

 
Reply to this topicStart new topic

creating textbox at run time

katore
post 11 Jul, 2008 - 02:31 AM
Post #1


New D.I.C Head

*
Joined: 11 Jul, 2008
Posts: 1

i generated a text box at runtime while clicking on button through arrays and i set a counter to it but the problem is that, when i run and clicked on button it displays only one textbox i want to generate more please help me to solve that problem. smile.gif smile.gif


Attached File(s)
Attached File  textbox_at_runtime.txt ( 955bytes ) Number of downloads: 18
Attached File  textbox_at_runtime.txt ( 955bytes ) Number of downloads: 9
User is offlineProfile CardPM

Go to the top of the page


zakary
post 11 Jul, 2008 - 05:15 AM
Post #2


D.I.C Regular

Group Icon
Joined: 15 Feb, 2005
Posts: 382



Thanked 4 times

Dream Kudos: 175
My Contributions


Please post your code here. I know most of use myself included will not open files from people we do not know
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 11 Jul, 2008 - 07:15 AM
Post #3


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,763



Thanked 70 times

Dream Kudos: 400

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


You have two issues. Your counter is local to the method, so it's always zero. Also, you're creating one text box on top of the other. Try spacing them next to each other.

csharp

// use a counter inside the form, not the method.
int textBoxCounter = 0;

private void button5_Click(object sender, EventArgs e) {
textBoxCounter++;
TextBox newtextbox = new TextBox();
newtextbox.Size = new Size(60, 40);
newtextbox.Location = new Point(150, 40 + (40 * textBoxCounter));
newtextbox.Visible = true;
newtextbox.TabIndex = textBoxCounter;
Controls.Add(newtextbox);
}
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 08:26PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month