I’m working in a winform where I created a label in a panel. As I append text words, how do I cause the label to go to the next line when the text fills the width of the panel?
I tried the following code but it doesn’t look right
int lbl= 150;
if (Lbl_full_list.Width > o)
{
my_Lbl.Text += "\n" + comboBox1.Text;
o += 150;
}
else
{
my_Lbl.Text.Text += " , " + comboBox1.Text;
}
The easiest solution is to:
my_Lbl.AutoSizetofalse.my_Lblin the containing panel toFill.Now
my_Lblwill automatically start a new row when a line of text exceeds the label’s width. Plus you get dynamic layout when the containingPanelresizes.Note that you should create a dedicated
Panelfor this purpose. If you have moreControlsinside the containingPanelyou are currently using just create a new one only for this purpose (containingmy_Lbl).