Three solutions to the problem that the Text content of the Label in C#Winform is too long and cannot be wrapped

Solution to the problem that the Text content of Label in C#Winform is too long and cannot wrap

1. Set the AutoSize property of Label to False, and manually modify the size of Label

Disadvantages: When the length of the content exceeds the set size, the extra content will not be displayed. Therefore, this method is suitable for use when the content length is basically determined

2. Set the Dock of the Label to FILL, and set the AutoSize property to False

Disadvantage: Label will occupy the position of other controls and affect the layout. Therefore, when using this method, it is best to add a Panel or GroupBox control to Label

3. By judging the length of the content, dynamically set the size of the Label

Implementation example:
int LblNum = str.Length; //Label content length  
int RowNum = 10; //The number of characters displayed in each line  
float FontWidth = label1.Width / label1.Text.Length; //The width of each character  
int RowHeight= 15; //The height of each row  
int ColNum = (LblNum - (LblNum / RowNum) * RowNum) == 0 ? (Lbl

Guess you like

Origin blog.csdn.net/qq_30725967/article/details/132250750