Ich schreibe eine Anwendung in .NET 2.0 und ich brauche die Funktionalität eines FlowLayoutPanel
von WinForms. Dies ist der Code, den ich mit dem kam ich verwende jetzt (meist mit Labels):FlowLayoutPanel in CF.NET
/// <summary>
/// Flowable layout panel
/// </summary>
public partial class FlowLayoutPanel : Panel
{
public FlowLayoutPanel()
{
InitializeComponent();
}
/// <summary>
/// Flow the layout of the panel. Required before presentation.
/// </summary>
public void Layout()
{
int top = 0;
// Set control position
foreach (Control ctrl in this.Controls)
{
ctrl.Top = top;
// Account for the scrollbar
ctrl.Width = this.Width - 17;
top += ctrl.Height;
}
}
}
Das Panel zu dem Formular hinzugefügt wird (in meinem Fall eine dynamisch generierte Registerkarte), dann füge ich hinzu Steuerelemente in der Codeansicht des Formulars, wie folgt:
panel.Controls.Add(new Label() { Text = "Item name", Font = boldTahoma });
panel.Controls.Add(new Label() { Text = item.ItemName });
panel.Controls.Add(new Label() { Text = "Category", Font = boldTahoma });
panel.Controls.Add(new Label() { Text = item.Category });
panel.Controls.Add(new Label() { Text = "Quantity", Font = boldTahoma });
panel.Controls.Add(new Label() { Text = item.Quantity });
panel.Layout();
Also ich nehme an, ich habe zwei Fragen. Es funktioniert, aber gibt es einen besseren Weg, dies zu tun (vor allem, so muss ich nicht Layout()
jedes Mal anrufen) und gibt es eine Möglichkeit, so dass ich Etiketten Auto-Höhe machen kann? Vielen Dank.