C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
dynamically controlling windows form objects Posted by alaahelmy on 26 Nov 2003 at 6:38 AM
hi all
is there a way to dynamically add user defined number(the number is not known in the design time) of TextBox objects to a windows form in runtime

my problem is generating the TextBox object identifier dynamically in the runtime
I am C# beginner &I don't know the c# compiler ristrictions

thanks for cooperation
Report
Re: dynamically controlling windows form objects Posted by pingpong on 26 Nov 2003 at 8:39 AM
Yes, no problem.

// in Form1.cs

// the text boxes
TextBox[] textBoxes;

void AddThem(int count)
{
   this.SuspendLayout();  // not necessary, but makes the new text boxes all appear at once

   textBoxes = new TextBox[count];

   // say we add them all one under the other at x = 10, y = 10 with 10 space betwen them
   for(int i = 0; i < count; i++)
   {
      // initialize it
      textBoxes[i] = new TextBox();
      textBoxes[i].Text = string.Format("TextBox #{0}", i);
      textBoxes[i].Location = new Point(10, 10 + i * textBoxes[i].Height + 10);
      // add it to the form
      this.Controls.Add(textBoxes[i]);      
   }

   this.ResumeLayout();
}


: hi all
: is there a way to dynamically add user defined number(the number is not known in the design time) of TextBox objects to a windows form in runtime
:
: my problem is generating the TextBox object identifier dynamically in the runtime
: I am C# beginner &I don't know the c# compiler ristrictions
:
: thanks for cooperation
:

Report
Re: dynamically controlling windows form objects Posted by alaahelmy on 28 Nov 2003 at 6:08 AM
dear pingpong
thanks alot for ur help and support
: Yes, no problem.
:
:
: // in Form1.cs
: 
: // the text boxes
: TextBox[] textBoxes;
: 
: void AddThem(int count)
: {
:    this.SuspendLayout();  // not necessary, but makes the new text boxes all appear at once
: 
:    textBoxes = new TextBox[count];
: 
:    // say we add them all one under the other at x = 10, y = 10 with 10 space betwen them
:    for(int i = 0; i < count; i++)
:    {
:       // initialize it
:       textBoxes[i] = new TextBox();
:       textBoxes[i].Text = string.Format("TextBox #{0}", i);
:       textBoxes[i].Location = new Point(10, 10 + i * textBoxes[i].Height + 10);
:       // add it to the form
:       this.Controls.Add(textBoxes[i]);      
:    }
: 
:    this.ResumeLayout();
: }
: 

:
: : hi all
: : is there a way to dynamically add user defined number(the number is not known in the design time) of TextBox objects to a windows form in runtime
: :
: : my problem is generating the TextBox object identifier dynamically in the runtime
: : I am C# beginner &I don't know the c# compiler ristrictions
: :
: : thanks for cooperation
: :
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.