设置XtraForm标题居中

原文: 设置XtraForm标题居中

    public class CustomFormPainter : FormPainter
    {
        public CustomFormPainter(Control owner,DevExpress.Skins.ISkinProvider provider)
            : base(owner,provider)
        {
        }
        protected override void DrawText(DevExpress.Utils.Drawing.GraphicsCache cache)
        {
           
            string text = Text;
            if (text == null || text.Length == 0 || TextBounds.IsEmpty) return;
            using (AppearanceObject appearance = new AppearanceObject(GetDefaultAppearance()))
            {
                appearance.TextOptions.Trimming = Trimming.EllipsisCharacter;
                appearance.TextOptions.HAlignment = HorzAlignment.Center;
                appearance.Font = new Font(appearance.Font.Name,30,FontStyle.Bold,appearance.Font.Unit,appearance.Font.GdiCharSet,appearance.Font.GdiverticalFont);
                if (AllowHtmlDraw)
                {
                    DrawHtmlText(cache,appearance);
                    return;
                }
                Rectangle r = RectangleHelper.GetCenterBounds(TextBounds,new Size(TextBounds.Width,CalcTextHeight(cache.Graphics,appearance)));
                DrawTextShadow(cache,appearance,r);
                cache.DrawString(text,appearance.Font,appearance.GetForeBrush(cache),r,appearance.GetStringFormat());
            }
        }
    }
这样用
    public partial class frmMain : DevExpress.XtraEditors.XtraForm
    {
        static frmMain()
        {
            SkinManager.EnableFormSkins();
        }
        public frmMain()
        {
            InitializeComponent();
        }
        protected override FormPainter CreateFormBorderPainter()
        {
            return new CustomFormPainter(this,LookAndFeel);
        }
    }

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...