以下代码为正确实现。
this.statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
this.toolStripStatusLabel1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
this.toolStripStatusLabel1.Text = "xxxx © 2019-"+System.DateTime.Today.Year.ToString()+" 信息中心 设计开发";
添加转载:转帖:https://blog.csdn.net/cdhql/article/details/6119774
[C#]解决statusStrip控件上的项目不能靠右对齐的问题
在c#中用到了状态栏控件StatusStrip,但当我想把StatusStrip上某个StatusLabel靠右对齐时出了问题。
按照MSDN中的办法,是设置ToolStripStatusLabel的Alignment属性为Right。不过我在设计界面的属性窗口中找不到Alignment。
就算加入代码toolStripStatusLabel2.Alignment = ToolStripItemAlignment.Right; 也还是没什么效果。
后来我找到两种方法解决这个问题:
方法一:
在状态栏所有项目(StatusLabel、ProgressBar、DropDownButton等)前添加一个空白的StatusLabel (Text属性为空),并将其Spring属性设为True。
Spring属性的作用是设置该项是否填满剩余空间,设为True以后,当程序运行时后面的项就都挤到右边,实现靠右对齐了。
如果更进一步,需要一部分项靠左,一部分靠右,那就在两部分中间插入空白StatusLabel,同时设其Spring属性为True。
这种方法比较简单,不用手工添加代码。首选!
方法二:
这个方法是我无意中发现的。
设置StatusStrip控件的LayoutStyle属性为HorizontalStackWithOverflow 或 StackWithOverflow。
然后在代码中修改状态栏上某项的Alignment为Right,这次就有靠右的效果了。
例如: this.toolStripStatusLabel1.Alignment = ToolStripItemAlignment.Right;
注意如果是多个项,那靠左对齐的从左往右排列,靠右对齐的从右往左排列。
问题是基本解决了,只是我还是不知道为什么在属性窗口里ToolStripStatusLabel没有Alignment属性。从网上搜集的帖子看,好像其他人都没这个问题啊?
有谁知道的话告诉我。对了,我用的是VS2005 版本8.0.50727.42。
以下转自:https://www.cnblogs.com/xiaowie/p/8624387.html
态栏用于显示用户状态的简短信息。
StatusStrip控件是由system.windows.forms.statusStrip类提供,作用是在应用程序中标识对话框底部的一栏,通常用于显示应用程序当前状态的简短信息。
在StatusStrip中可以使用toolstrip中介绍的控件中的三个----Toolstripdropdownbutton、toolstripprogressbar、toolstripSplitbutton
还有一个控件就是StatusStrip专用的,即StatusStripStatuslabel,作用就是使用文本和图像用户显示应用程序当前状态的信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|