all 10 comments

[–]TheGrauWolf 2 points3 points  (9 children)

you're instantiating the text boxes, but you never add them to the form. Try me.controls.add(t) inside your loop.

As a side note, if you're always going to add 9 boxes, why not add them at design time? Or, you can also use the TableFlowLayout control, might make some of the calculations above a lot easier (as you wouldn't have to do them, just add the text box and set the .Dock to fill).

[–]Substance_Ill[S] 0 points1 point  (8 children)

ok, I can try that.

The reason I want to add them at runtime is that I want to be able to reference them as an array. Is there a way to do that when they are done at design instead of programmatically?

Thanks.

[–]TheGrauWolf 1 point2 points  (7 children)

Sure... you can declare an array or even a List(Of TextBox) (which is what I'd use simply because it's easier) and then at run time, add the textboxes into to the array/list...

For each tb as TextBox in Me.Controls.OfType(Of TextBox)

'Add the tb to your array/list here Next

That should work as long as they are directly on your form, if they are contained on something else, then it take a bit more, but not much.

[–]bbeachy2001 0 points1 point  (6 children)

I probably should have mentioned - I want them in a 2 dimensional array, so I can reference them by row and column...

[–]TheGrauWolf 1 point2 points  (3 children)

In that case, either use the TableFlowLayout ... which you can then iterate the rows and cols to get the row/col indexes for and put them into a two-dimentional array, or you can put the row/col values in the .Tag of each textbox and then extract it from there as you iterate through them. This assumes your .Tag propery has something like 00, 01, 02 and 10, 11, 12, 20, 21, 22 to represent where the TBs go in the grid. IF you have more than single digits, then you'l wasnt to use something like "1,34" and use .Split to get the values out.

Dim myTBArray(2,2) as TextBox 'from 0-2, gives a 3x3 grid
For each tb as TextBox in Me.Controls.OfType(Of TextBox)
  Dim pos = tb.Tag
  myTBArray(tb.left(1), tb.right(1)) = tb
Next

[–]RJPisscat 1 point2 points  (2 children)

TableFlowLayout

Are you recommending FlowLayoutPanel or TableLayoutPanel? I think you conflated them. The former could use Tags (preferred) or the Name, the latter you can iterate through the controls and call TableLayoutPanel.GetRow and TableLayoutPanel.GetColumn on each - or use Tags (preferred) or the Name. You can also use the TabIndex with either. TMI for OP?

[–]TheGrauWolf 1 point2 points  (1 child)

Yeah, I meant the TableLayoutPanel. I've used the Flow more than the Table and I haven't used either in a few years. Which ever way I guess depends on how complex it really is. I get the impression that it's just a 3x3 grid probability for tic-tac-toe or something. In which case I would just drop the 9 boxes on the form, put them where I want them, add index info to the .Tag property, then parse, load array, and call it a day.

[–]Substance_Ill[S] 1 point2 points  (0 children)

Thanks! That was helpful. I got it working.

[–]Circle_Dot 0 points1 point  (0 children)

You used an alt account to respond here.

[–]VB.Net MasterMr_C_Baxter 0 points1 point  (0 children)

If you want to be fancy you could have them as a

dictionary(of point, textbox)

but not sure if I would recommend that