如何在标签中显示2D数组的值?

时间:2018-06-01 22:48:44

标签: c# winforms

我有一个2D数组,如下所示。我想在Windows窗体上使用标签显示它,因此它采用表格格式(行和列)。如何实现此目的?

Error using ode45
Too many input arguments.

Error in task1 (line 41)
    [t_builtin,fun_builtin] = ode45(func, t, 0, opts);

1 个答案:

答案 0 :(得分:0)

使用monospacedConsolas字体并填充左侧空格如下:

Label label = new Label();
this.Controls.Add(label);
label.Size = new Size(500, 500); // Enter custom size or use Graphics.MeasureString method to find proper size dynamically
label.AutoSize = false;
label.Font = new Font("Consolas", 8);
for (int i = 0; i < map.GetLength(0); i++)
{
    for (int j = 0; j < map.GetLength(1); j++)
    {
        label.Text += map[i, j].PadLeft(5, ' ');
    }
    label.Text += Environment.NewLine;
}
相关问题