用心计较般般错 安心自守事事宽

cgl 坚持、努力终有所获
  新随笔  :: 管理

设置XtraForm标题居中

Posted on 2015-12-28 15:31  用心计较般般错 安心自守事事宽  阅读(637)  评论(1编辑  收藏  举报
    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);
        }
    }