将Tittle bar文本形成以C#为中心 [英] Form Tittle bar text to center in C#

查看:55
本文介绍了将Tittle bar文本形成以C#为中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



如何在C#中将文本设置为表格中心条。



请帮助我。



谢谢和问候,

Kamlesh Nikam

解决方案

< blockquote>如果它的Winform chk这个链接:



中心对齐表格标题栏的TExt。 [ ^ ]



  private   void  Center_Text()
{
Graphics g = .CreateGraphics();
Double startingPoint =( this .Width / 2 ) - (g.MeasureString( this .Text.Trim(), this 。字体)。宽度/ 2 );
Double widthOfASpace = g.MeasureString( this .Font).Width;
字符串 tmp = ;
Double tmpWidth = 0 ;
while ((tmpWidth + widthOfASpace)< startingPoint)
{
tmp + = ;
tmpWidth + = widthOfASpace;
}
.Text = tmp + .Text.Trim() ;
}
私有 void Form2_Load( object sender,EventArgs e)
{
Center_Text();
}


没有内置方式来执行此操作:标准是表单标题显示在左侧下一个到图标/系统框,你不应该真的改变它 - 它违反了正常的UI准则。



如果你想要你可以做到:但它是不好,或者不简单: http: //stackoverflow.com/questions/11947314/how-to-center-align-the-title-bar-text-in-windows-form [ ^ ]



个人?我不会。


Hi All,

How to set text to center of form tittle bar in C#.

Please help me.

Thanks and regards,
Kamlesh Nikam

解决方案

If its Winform chk this link :

Center Align the TExt of Form Title Bar.[^]

private void Center_Text()
       {
           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();
       }
       private void Form2_Load(object sender, EventArgs e)
       {
           Center_Text();
       }


There is no "built in" way to do this: the standard is that form titles appear at the left next to the icon / system box and you shouldn't really change that - it goes against the normal UI guidelines.

You can do it if you want though: but it's not nice, or it's not simple: http://stackoverflow.com/questions/11947314/how-to-center-align-the-title-bar-text-in-windows-form[^]

Personally? I wouldn't.


这篇关于将Tittle bar文本形成以C#为中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆