为文本框创建二维数组

发布于 2024-10-02 09:56:25 字数 221 浏览 3 评论 0 原文

所以我试图创建一个 8X8 的文本框网格。当我需要搜索文本框时,我希望能够访问它们。我考虑过考虑嵌入列表(即 List>),其中内部列表有 8 个插槽,外部列表也有 8 个。我想知道是否有更简单的方法。

另外,我如何将表单中的文本框添加到这个二维数组中?

感谢您的帮助。

-刘易斯

So I'm trying to create an 8X8 grid of textboxes. I want to have the ability to also access the textboxes when I need to search through them. I have looked into considering an embedded List (i.e. List<List<TextBoxes>>) Where the inner list has 8 slots and the outer lists also has 8. I was wondering if there was an easier way.

Also how would I add my textboxes from my form into this 2d array?

Thanks for the help.

-Lewis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

标点 2024-10-09 09:56:25

您可以使用 TextBox[,] 来实现此目的:

private TextBox[,] textboxes;

public YourClass() {
    // Add this after the text boxes have actually been set up...

    textboxes = new TextBox[,] {
        {textbox00, textbox01, textbox02, ...},
        {textbox10, textbox11, textbox12, ...},
        ,,,
    };
}

然后您可以将 textbox00 访问为 textboxes[0,0], textbox56 作为 textboxes[5,6] 等。

You could use a TextBox[,] for this purpose:

private TextBox[,] textboxes;

public YourClass() {
    // Add this after the text boxes have actually been set up...

    textboxes = new TextBox[,] {
        {textbox00, textbox01, textbox02, ...},
        {textbox10, textbox11, textbox12, ...},
        ,,,
    };
}

Then you can access textbox00 as textboxes[0,0], textbox56 as textboxes[5,6], etc.

深海少女心 2024-10-09 09:56:25

试试这个:

private class Position
{
    internal int Row;
    internal int Col;
}

var txtBoxesDict=new Dictionary<Position, TextBox>();

txtBoxesDict.Add(new Position{Row=0,Col=0},txtBox0);

要访问第四行的第三个文本框,您可以使用:

MessageBox.Show(txtBoxesDict[new Position{Row=3, Col=2}].Text);

try this:

private class Position
{
    internal int Row;
    internal int Col;
}

var txtBoxesDict=new Dictionary<Position, TextBox>();

txtBoxesDict.Add(new Position{Row=0,Col=0},txtBox0);

To access thrid textbox in fourth row, you can use:

MessageBox.Show(txtBoxesDict[new Position{Row=3, Col=2}].Text);
戏剧牡丹亭 2024-10-09 09:56:25

使用标准二维数组 TextBoxes[8,8]

Use a standard 2D array TextBoxes[8,8]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文