У меня есть программа WinForms, которая при запуске устанавливает TableLayoutPanel. Я добавляю к нему другой набор TLP и устанавливаю тег, соответствующий цвету, который я буду sh рисовать:
private void Set_IO_Display()
{
// this sets up the TLP at run time. this all works fine. The TLPs set up here are referred to in `Update_GUI_Inputs()`
string Type; // these are all defined from an XML file
string Device = "ED527"; //these are examples
string Line = "1";//example
string label = "Test"; //example
string Colour = "Green"; //example
TableLayoutPanel IOTable = new TableLayoutPanel();
IOTable.ColumnCount = 6;
IOTable.RowCount = 1;
IOTable.Name = Device + "_" + Line;
#region AddLabels
IOTable.Controls.Add(new Label
{
Text = label,
TextAlign = ContentAlignment.MiddleCenter,
BorderStyle = BorderStyle.FixedSingle,
BackColor = Color.White,
Dock = DockStyle.Fill
}); // I add another 5 labels here
IOTable.Dock = DockStyle.Fill;
IOTable.Tag = Colour;
}
private void UpdateGUI_Inputs()
{
//this is this sub for the updates, which works okay
string I_Card_Name = "ED527_" + i.ToString();
TLP = TLP_IO_Info.Controls.Find(I_Card_Name, true).FirstOrDefault() as TableLayoutPanel;// <-- this works fine - the name given in Set_IO_Display() is found and I can do something with it.
lbl = TLP.GetControlFromPosition(4, 0) as Label;// <<-- this also works fine.
lbl.Invoke((MethodInvoker)delegate { lbl.BackColor = Color.FromName(TLP.Tag); }); //<-- the TLP tag is returned as null - Why?
}
Даже если TableLayoutPanel
и его дочерняя метка найдены, и я может делать что-то с ними, он не возвращает тег при вызове.
Как получить тег?