The status bar control statusstrip is used in C #, but an error occurs when I want to align a statuslabel on statusstrip to the right.
In msdn, set the alignment attribute of toolstripstatuslabel to right. However, I cannot find alignment in the design attribute window.
Even if you add toolstripstatuslabel2.alignment = toolstripitemalignment. Right;, it still has no effect.
Then I found two ways to solve this problem:
Method 1:
Add a blank statuslabel before all items in the status bar (statuslabel, progressbar, dropdownbutton, etc.) and set its spring attribute to true.
The spring attribute is used to set whether the item fills up the remaining space. After it is set to true, all the items after the program is run will be squeezed to the Right to align to the right.
If you need to move a part of the items to the left and a part to the right, insert a blank statuslabel in the middle of the two parts and set its spring attribute to true.
This method is relatively simple and you do not need to manually add code. First Choice!
Method 2:
I accidentally discovered this method.
Set the layoutstyle attribute of the statusstrip control to horizontalstackwithoverflow or stackwithoverflow.
Then, in the Code, modify the alignment of an item on the status bar to "right". This time, the result is "right.
Example: This. toolstripstatuslabel1.alignment = toolstripitemalignment. Right;
Note that if there are multiple items, the items are arranged from left to right in the left alignment and from right to left in the right alignment.
The problem is solved basically, but I still don't know why the toolstripstatuslabel does not have the alignment attribute in the attribute window. From the posts collected on the internet, it seems that no one else has this problem?