微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

设置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);
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐