开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 9901|回复: 4

【教程】取消RibbonPageGroup文字+PageGroup居右显示

[复制链接]

0

精华

5273

贡献

5986

赞扬

管理员

帖子
1172
软币
22465
在线时间
4450 小时
注册时间
2013-6-7

黄马甲

发表于 2014-7-8 11:02:19 | 显示全部楼层 |阅读模式
新增一个类,继承RibbonControl

[C#] 纯文本查看 复制代码
using System;
using System.Drawing;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Ribbon.ViewInfo;
using DevExpress.Utils;
using System.ComponentModel;

namespace testSpace
{
    public class Mribbon : RibbonControl
    {
        public Mribbon() : base() { }
        protected override RibbonViewInfo CreateViewInfo() { return new MribbonViewInfo(this); }

        #region 属性
        private HorzAlignment _FormCaptionAlignment = HorzAlignment.Default;
        [CategoryAttribute("MribbonSettings"), Description("窗体标题对齐方式"), DefaultValue(typeof(HorzAlignment), "Default")]
        public HorzAlignment FormCaptionAlignment
        {
            get { return _FormCaptionAlignment; }
            set { _FormCaptionAlignment = value; LayoutChanged(); }
        }


        bool _ShowGroupCaption = true;
        [CategoryAttribute("MribbonSettings"), Description("是否显示Group标题"), DefaultValue(true)]
        public bool ShowGroupCaption
        {
            get { return _ShowGroupCaption; }
            set { if (_ShowGroupCaption != value) _ShowGroupCaption = value; }
        }
        #endregion
    }

    public class MribbonViewInfo : RibbonViewInfo
    {
        public MribbonViewInfo(RibbonControl ribbon) : base(ribbon) { }
        protected override RibbonCaptionViewInfo CreateCaptionInfo()
        {
            return new MribbonCaptionViewInfo(this);
        }
        protected override RibbonPanelViewInfo CreatePanelInfo()
        {
            return new MribbonPanelViewInfo(this);
        }
    }

    #region 设置窗体标题对其模式
    public class MribbonCaptionViewInfo : RibbonCaptionViewInfo
    {
        public MribbonCaptionViewInfo(RibbonViewInfo viewInfo)
            : base(viewInfo)
        {

        }
        public HorzAlignment FormCaptionAlignment
        {
            get { return (ViewInfo.Ribbon as Mribbon).FormCaptionAlignment; }
        }

        protected override Rectangle CalcTextBounds()
        {
            var centerTextBounds = base.CalcTextBounds();
            if (FormCaptionAlignment == HorzAlignment.Near)
            {
                centerTextBounds.Offset(ContentBounds.X - centerTextBounds.X, 0);
            }
            if (FormCaptionAlignment == HorzAlignment.Far)
            {
                centerTextBounds.Offset(ContentBounds.Right - centerTextBounds.Right, 0);
            }
            return centerTextBounds;
        }
    }
    #endregion


    public class MribbonPageGroupViewInfo : RibbonPageGroupViewInfo
    {
        public MribbonPageGroupViewInfo(RibbonViewInfo viewInfo, RibbonPageGroup group) : base(viewInfo, group) { }

        //设置Group右对齐
        public override void CalcViewInfo(Rectangle bounds)
        {
            if (object.Equals(PageGroup.Tag, "AlignRight"))
            {
                int offset = ViewInfo.Bounds.Right - bounds.Right;
                if (offset > 5)
                    bounds.Offset(offset, 0);
            }
            base.CalcViewInfo(bounds);
        }

        //是否显示群组标题
        protected override DevExpress.Utils.Drawing.GroupObjectInfoArgs SetupDrawArgs()
        {
            DevExpress.Utils.Drawing.GroupObjectInfoArgs args = base.SetupDrawArgs();
            args.ShowCaption = (base.Ribbon as Mribbon).ShowGroupCaption;
            return args;
        }
    }
    public class MribbonPanelViewInfo : RibbonPanelViewInfo
    {
        public MribbonPanelViewInfo(RibbonViewInfo viewInfo) : base(viewInfo) { }
        protected override RibbonPageGroupViewInfo CreateGroupViewInfo(RibbonPageGroup group)
        {
            return new MribbonPageGroupViewInfo(ViewInfo, group);
        }
    }

}

评分

参与人数 2软币 +1 赞扬 +2 收起 理由
maple + 1 感谢分享
Cactus_CC + 1 + 1 赞一个

查看全部评分

回复

使用道具 举报

头像被屏蔽

0

精华

-4

贡献

0

赞扬

禁止发言

帖子
29
软币
177
在线时间
18 小时
注册时间
2014-9-16
发表于 2014-10-17 12:17:53 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-11-23 20:35

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表