居中对齐表单标题栏的文本 [英] Center Align the Text of Form Title Bar

查看:90
本文介绍了居中对齐表单标题栏的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现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 !!!

推荐答案

这是使Windows窗体在c#中的标题栏中的文本居中对齐的代码.

编写以下方法,然后在Form Load事件中调用它.
This is the Code to Center Align Text in title Bar in Windows Form in c#.

Write The Following Method and call it in Form Load event.
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();
        }


阅读http://msdn.microsoft.com/en-us/library/system.windows.forms.buttonrenderer [
Read msdn content at http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.aspx[^] and http://msdn.microsoft.com/en-us/library/system.windows.forms.buttonrenderer[^] links


这篇关于居中对齐表单标题栏的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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