c# - 文本框值放入 int 数组中

标签 c# winforms visual-studio-2010 visual-studio textbox

我的表单如下所示:

http://content.screencast.com/users/TT13/folders/Jing/media/7689e48c-9bd6-4e22-b610-656b8d5dcaab/2012-07-06_0347.png

x, y, A,B,C 是矩阵。 x 右侧的文本框被命名为 x1,...,x6A 右侧的文本框被命名为

a11,...,a16
...
a61, ... ,a66

它们都是整数。我想要做的是将这些值放入数组中,例如:

x=(20,...,756);

将 A 放入二维数组,如 a[1][1]=932 ... a[6][6]=666

如果是,怎么办?与分组框?我不知道如何解决这个问题。提前谢谢

最佳答案

看到您的控件的名称嵌入了矩阵位置,我们可以编写
这里没有错误检查,我假设数字总是整数......

    int[] xMatrix = new int[6];
    int[,] aMatrix = new int[6,6];

    foreach (Control control in this.Controls) 
    { 
        if (control is TextBox) 
        { 
            string pos = control.Name.SubString(1);
            if(control.Name.StartsWith("a"))
            {
                int matrixPos = Convert.ToInt32(pos) ;
                int x = (matrixPos / 10) - 1;
                int y = (matrixPos % 10) - 1;
                aMatrix[x,y] = Convert.ToInt32(control.Text);
            }
            else if(control.Name.StartsWith("x")
            {
                int arrayPos = Convert.ToInt32(pos) - 1;
                xMatrix[arrayPos] =  Convert.ToInt32(control.Text);
            }
        } 
    } 

关于c# - 文本框值放入 int 数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11353587/

相关文章:

c# - 在 .dll 文件和 .cs 上运行 Fortify

c# - 如何在 DOT NET CORE 中设置 HttpClient 请求的 "custom"Content-Type?

c# - 绘制 8bpp 位图时如何使调色板中的颜色透明

.net - 是否可以在 Windows 窗体中显示命令窗口?

c# - SaveFileDialog 在 Windows XP 中无法返回

visual-studio-2010 - Visual Studio 2010 MVC 2(导入 2008 项目) - 发布失败 - System.Web.Routing.RouteValueDictionary 存在于两者中

c# - 如何确定在特定坐标处是否有物体位于平面上?

c# - imageList控件的使用方法

visual-studio-2010 - Crystal 报表每页只显示一行

c# - 如何从 IObservable<T> 自动更新数据网格