加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

设置XtraForm标题居中

发布时间:2020-12-15 05:26:10 所属栏目:Java 来源:网络整理
导读:原文: 设置XtraForm标题居中 public class CustomFormPainter : FormPainter { public CustomFormPainter(Control owner,DevExpress.Skins.ISkinProvider provider) : base (owner,provider) { } protected override void DrawText(DevExpress.Utils.Drawing
原文: 设置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);
        }
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读