View Single Post
Old Apr 15th, 2008, 4:07 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,010
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: cration of a new control, problem with adding new controls

Are you trying to actually create a new control (ie, a custom control), or are you just trying to stick a bunch of stuff onto a panel? If it's the former, it's a little involved, particularly if you want design-time support (support in the drag-and-drop 'forms designer'). If it's the latter, you can just add them in the designer. If you need to iterate through them with array notation, you add the TextBoxes (or whatever) in the designer, and give them descriptive names (not necessary, but a good habit to get into). Then, in your code, you create an array of TextBoxes, and assign the references:
C# Syntax (Toggle Plain Text)
  1. TextBox[] textBoxArray = new TextBox[numberOfTextBoxes];
  2. textBoxArray[0] = txtInput;
  3. textBoxArray[1] = txtOutput;
  4. textBoxArray[2] = txtSomethingElse;
  5. // and so on
Now you can process them in a loop, which is probably why you want to use an array:
C# Syntax (Toggle Plain Text)
  1. for(int x=0; x<textBoxArray.Length; ++x)
  2. textBoxArray[x].Text = x.ToString();
Remember that even though you can create an array of controls, you still need to initialize each element of the array appropriately. The designer is the easiest way to do this; otherwise, you need to set the width, height, location, etc of each one individually.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote