I have a winform app with a problem, a method dynamically add controls to a TableLayoutPanel
tableLayoutPanel1.Controls.Clear();
foreach (Equivalencia equivalencia in equivalencias)
{
FlowLayoutPanel panel1 = new FlowLayoutPanel()
{
BackColor = Color.IndianRed,
AutoSize = true,
AutoScroll = true,
FlowDirection = System.Windows.Forms.FlowDirection.TopDown,
WrapContents = false,
BorderStyle = BorderStyle.FixedSingle,
Dock = DockStyle.Top,
ContextMenuStrip = contextMenuStrip1
};
FlowLayoutPanel panel2 = new FlowLayoutPanel()
{
BackColor = Color.IndianRed,
AutoSize = true,
AutoScroll = true,
FlowDirection = System.Windows.Forms.FlowDirection.TopDown,
WrapContents = false,
BorderStyle = BorderStyle.FixedSingle,
Dock = DockStyle.Top,
ContextMenuStrip = contextMenuStrip1
};
tableLayoutPanel1.Controls.Add(panel1, 0, i++);
tableLayoutPanel1.Controls.Add(panel2, 0, j++);
foreach (MyItem ma in equivalencia.Lefts)
{
panel1.Controls.Add(new Label() { Text = ma.name });
}
foreach (MyItem mb in equivalencia.Rigths)
{
panel2.Controls.Add(new Label() { Text = mb.name });
}
}
Why use a panel within the TableLayoutPanel ?, because I need to display a relationship between a list of things. For example in some element 10 may have only the left side and one on the right side or 2-4 , 1-3 ,4-1 etc.
This code used when the form loads, when a new object is created or when an object is deleted
When the form is first loaded, the control looks great without problem.
The problem occurs when an object is created or deleted, this deletes the contents of the TableLayoutPanel and draw one at each control, this process takes a lot and is very annoying visually.
Upload a video so they can see what I mean
A tried remove the BackColor, set AutoSize to false remove the Dock but the behavior persists
Aucun commentaire:
Enregistrer un commentaire