我是C#的新手,很抱歉,如果这是一个愚蠢的问题!
我目前在代码中有3个表单,我想更改第三个表单上的标签的位置。以下是我试图指定的代码的一部分:
Form ThirdForm = new Form();
int horizontalCount;
ThirdForm.label[horizontalCount - 1].Top = label[16].Top;
ThirdForm.label[horizontalCount - 1].Left = label[16].Left;
这将返回错误:
错误CS1061'Form'不包含'label'的定义,也没有扩展方法'label'接受类型'Form'的第一个参数(你是否缺少using指令或汇编引用?)HID PnP演示
使用此方法将标签添加到表单中:
Label[] createlabels(Image[] tiles, Bitmap Img, int[] tileOrder, Form form)
{
int i = 0; int val;
for (int j = 0; j < ROW_COUNT; j++)
for (int k = 0; k < COLUMN_COUNT; k++)
{
//val = gridVal[j, k];
label[i] = new Label();
label[i].Font = new Font("Microsoft Sans Serif", 15F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0)));
label[i].Width = Img.Width / COLUMN_COUNT;
label[i].Height = Img.Height / ROW_COUNT;
label[i].Left = k * (int)label[i].Width;
label[i].Top = j * (int)label[i].Height;
label[i].Tag = 0;
label[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
if (i != 15)
{
string LabelNumber = i.ToString();
string TileNumber = tileOrder[i].ToString();
label[i].Image = tiles[tileOrder[i]];
label[i].BorderStyle = BorderStyle.FixedSingle;
label[i].Text = TileNumber;
}
else
{
label[i].BackColor = Color.Black;
label[i].BorderStyle = BorderStyle.None;
label[i].Text = "";
label[i].Visible = false;
z = i;
whiteTileLeftLocation = label[i].Left;
whiteTileTopLocation = label[i].Top;
verticalCount = 4;
horizontalCount = 4;
}
form.Controls.Add(label[i]);
i++;
}
return label;
}
我做错了什么?
非常感谢任何帮助!