hi
i have 64 textbox that on runtime be appear on design i didn't collect them and now i want to reach to one of them and find the i,j (i,j are 2 dimention array form these textbox) and then go to next textbox how i can do that?
i don't know is it clear or not if it isn't say i will put my source here

Recommended Answers

All 9 Replies

Not clear. Please give the source...

c = new TextBox[rowID, columnID];
            for (int i = 0; i <= rowID-1; i++)
            {
                for (int j = 0; j <= columnID-1; j++)
                {
                   c[i, j] = new TextBox();
                   c[i, j].Width = 30;
                   c[i, j].Height = 30;
                   c[i, j].BackColor = Color.Red;
                   c[i, j].BorderStyle = BorderStyle.Fixed3D;
                   c[i, j].TextAlign = HorizontalAlignment.Center;
                   c[i, j].Text = "a".ToUpper();
                   c[i, j].Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
                   //c[i, j].Focus = false;
                   if (i == 0 & j == 0)
                   {
                       c[i, j].Left = this.Width - 150 - (columnID * c[i, j].Width);
                       c[i, j].Top = this.Height - 470;
                       this.Controls.Add(c[0, 0]);
                   }
                   if (i == 0 & j != 0)
                   {
                       c[i, j].Left = c[0, j - 1].Left + c[i, j].Width;
                       c[i, j].Top = c[0, j - 1].Top;
                       this.Controls.Add(c[i, j]);
                   }
                   if (j == 0 & i != 0)
                   {
                       c[i, j].Left = c[i - 1, 0].Left;
                       c[i, j].Top = c[i - 1, 0].Top + c[i, j].Height;
                       this.Controls.Add(c[i, j]);
                   }
                   if (i != 0 & j != 0)
                   {
                       c[i, j].Left = c[i - 1, j - 1].Left + c[i, j].Width;
                       c[i, j].Top = c[i - 1, j - 1].Top + c[i, j].Height;
                       this.Controls.Add(c[i, j]);
                   }

                }
            }

this is my code and i want reach each textbox that appear and get its i,j

commented: Use code tags. -2

Do you know the textbox's on the form that appear so you can search your array of TextBox controls (c[,]), or are you needing to enumerate through all controls on the form for textboxes first?

Yes I know it

for (int i = 0; i <= rowID-1; i++)
{
    for (int j = 0; j <= columnID-1; j++)
    {
         if (c[i,j].Equals(myFormsTextBox))
             ;//do something
     }
}

Use TableLayoutPanel.

int col = 5, row = 5;
            tableLayoutPanel1.RowCount = row;
            tableLayoutPanel1.ColumnCount = col;
            tableLayoutPanel1.AutoSize = true;

            TextBox[,] a = new TextBox[row, col];
            for (int i = 0; i <= a.GetUpperBound(0); i++)
            {
                for (int j = 0; j <= a.GetUpperBound(1); j++)
                {
                    a[i, j] = new TextBox();
                    tableLayoutPanel1.Controls.Add(a[i, j]);
                    tableLayoutPanel1.SetCellPosition(a[i, j], new TableLayoutPanelCellPosition(j, i));

                }
            }

thanks but with tableLayoutPanel1 my design crashed
you know i want to make a corssword with different appreance
like this that i will attach
i have a table in my sqlDB that its feilds are TableID,RowID,ColumnID,CellStatus(Fill,Empty,Green),CellContent

and i get row and column from db but in rows 3,4,5,6,....
my design is crashed and the textboxes are not in the correct place with tableLayoutPanel1 is awful on runtime. Do you have any idea for creating this table and others like it? plz help

and this is my picture

and these are other tables and their answers
How i can make this kind of puzzle? what is the algorithm?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.