【发布时间】:2016-05-21 12:27:26
【问题描述】:
我有动态创建的 NxM 文本框。 用户用整数填充文本框。 我需要使用放入文本框的数据创建表 NxM。 我需要它来做矩阵计算。
我该怎么做?我可以为每个循环执行此操作吗?
我有这段代码,它给了我 NxM 文本框:
for (int i = 0; i <= verticalCount; i++)
{
if (i == verticalCount)
{
for (int j = 0; j < horizontalValue; j++)
{
var xEnd = 100 + 80 * verticalCount; ;
var yEnd = 100 + 60 * j;
var textBoxNM = new TextBox();
textBoxNM.Name = string.Format("TextBox_{0}_{1}", i, j);
textBoxNM.Location = new Point(xEnd, yEnd);
textBoxNM.Size = new System.Drawing.Size(50, 25);
Step2.Controls.Add(textBoxNM);
string end = string.Format("result = ", i + 1);
newLabel(end, xEnd - 60, yEnd, Step2);
}
}
else
{
for (int j = 0; j < horizontalValue; j++) //
{
var x = 20 + 80 * i;
var y = 100 + 60 * j;
if (j < horizontalValue)
{
newTextbox(x, y, Step2);
string nbr = string.Format("x{0}", i + 1);
newLabel(nbr, x + 50, y, Step2);
}
}
}
}
我有用 c++ 编写的代码,我正在尝试创建它的 windows 应用程序。
谢谢!
编辑:
public void button2_Click(object sender, EventArgs e)
{
var verticalCount = Convert.ToInt32(comboBox1.Text);
var horizontalValue = Convert.ToInt32(comboBox2.Text);
int[,] tbArray;
tbArray = new int[,] { { horizontalValue , verticalCount } };
foreach (Control ShouldBeTextBox in this.Controls)
{
if (ShouldBeTextBox is TextBox)
{
if (ShouldBeTextBox != null)
{
int x = horizontalValue;
int y = verticalCount;
var tag = ShouldBeTextBox.Tag as int[];
string a = Convert.ToString(tag);
MessageBox.Show(a);
tbArray[tag[x], tag[y]] = Convert.ToInt32(ShouldBeTextBox.Text);
}
else
MessageBox.Show("Fill all parameters");
}
}
}
【问题讨论】:
-
向我们展示您当前代码的相关部分。
-
感谢您对此感兴趣!我编辑了主题。
-
这并不是完全可以帮助我的。我有用 c++ 编写的函数,它们对矩阵进行计算,我只想传输这些函数并将其用作 c# 中的方法。搜索枢轴列、乘以列等功能...而且我希望整个应用程序使用文本框、标签和按钮。
-
您可以使用DataGridView。您还可以使用 TableLayoutPanel 并将 TextBox 控件添加到表格布局面板。
标签: c# c++ winforms visual-studio