本文介绍了居中对齐表单标题栏的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何实现System.Windows.Forms.VisualStyles的内容对齐枚举.
它包含使字幕文本对齐的Member ContentAlignment.
如何使用c#在Windows应用程序中实现它
在此先感谢!!!
How can I implement Content Alignment Enumeration of System.Windows.Forms.VisualStyles.
It contains Member ContentAlignment which align the Caption Text.
How to implement it in Windows Application using c#
Thanks in Advance !!!
推荐答案
private void UpdateTextPosition()
{
Graphics g = this.CreateGraphics();
Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
String tmp = " ";
Double tmpWidth = 0;
while ((tmpWidth + widthOfASpace) < startingPoint)
{
tmp += " ";
tmpWidth += widthOfASpace;
}
this.Text = tmp + this.Text.Trim();
}
这篇关于居中对齐表单标题栏的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!