所以这里是我的内置文本框的groupbox列数组。
我想要做的就是让用户选中它时会转到下一列并保持同一行。
例如:如果用户位于第2列第1行,则应该转到第3行的第1行。然而,根据我的代码发生的事情是,当它到达底部时它会下降,它会到达下一行并从那里上升。
private System.Windows.Forms.TextBox[,] statsBonus = new System.Windows.Forms.TextBox[6, 3]; // x, y
private System.Windows.Forms.GroupBox[] statsCol = new System.Windows.Forms.GroupBox[6];
for (int j = 0; j < statsCol.Length; j++)
{
statsCol[j] = new System.Windows.Forms.GroupBox();
this.statsCol[j].Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.statsCol[j].Location = new System.Drawing.Point(190 + j * 80, 20);
this.statsCol[j].Size = new System.Drawing.Size(72, 100);
this.statsCol[j].TabIndex = j + 1;
this.statsCol[j].TabStop = false;
this.statsCol[j].Text = statsLabel[j];
this.groupBox2.Controls.Add(statsCol[j]);
for (int i = 0; i < statsBonus.GetLength(1); i++)
{
statsBonus[j, i] = new System.Windows.Forms.TextBox();
this.statsBonus[j, i].Size = new System.Drawing.Size(35, 20);
this.statsBonus[j, i].Font = new System.Drawing.Font("Microsoft Sans Serif", 8, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.statsBonus[j, i].TabIndex = i + 1;
this.statsBonus[j, i].Anchor = AnchorStyles.None;
this.statsBonus[j, i].Dock = DockStyle.None;
Point pt = this.statsCol[j].DisplayRectangle.Location;
pt.X += (this.statsCol[j].DisplayRectangle.Width - this.statsBonus[j, i].Width) / 2;
pt.Y = 20 + i * 25;
this.statsBonus[j, i].Location = pt;
this.statsBonus[j, i].Text = "0";
statsBonus[j, i].Parent = this;
this.statsCol[j].Controls.Add(statsBonus[j, i]);
}
}
答案 0 :(得分:0)
评论或删除以下行
//this.statsCol[j].TabIndex = j + 1;
并在行下方变换
this.statsBonus[j, i].TabIndex = i + 1;
as
this.statsBonus[j, i].TabIndex = statsBonus.GetLength(1)*j + i+ 1;