码迷,mamicode.com
首页 > 其他好文 > 详细

Devexpress Ribbon Add Logo

时间:2019-01-15 23:36:59      阅读:405      评论:0      收藏:0      [点我收藏+]

标签:源代码   value   panel   count   ida   rms   wim   代码   designer   

技术分享图片

  一直在网上找类似的效果.在Devpexress控件里面的这个是一个Demo的.没法查看源代码.也不知道怎么写的.所以就在网上搜索了半天的.

 终于找到类似的解决办法.

 可以使用重绘制的办法的来解决.

[DesignerCategory("")]
    [Designer("")]
    public class RibbonLogoHelper : Component
    {
        private Image _Image;
        private RibbonControl _RibbonControl;

        public RibbonControl RibbonControl
        {
            get { return _RibbonControl; }
            set
            {
                if (value == _RibbonControl)
                    return;
                RibbonControl prevValue = _RibbonControl;
                _RibbonControl = value;
                OnRibbonChanged(prevValue, _RibbonControl);
            }
        }

        private void OnRibbonChanged(RibbonControl prevValue, RibbonControl ribbonControl)
        {
            if (prevValue != null)
                prevValue.Paint -= ribbonControl_Paint;
            if (ribbonControl != null)
            {
                ribbonControl.Paint += ribbonControl_Paint;
                ribbonControl.Invalidate();
            }
       
        }

        void ribbonControl_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            DrawRibbonLogo(e.Graphics);
        }


        public Image Image
        {
            get { return _Image; }
            set
            {
                if (value == _Image)
                    return;
                _Image = value;
                OnImageChanged();
            }
        }



        private void OnImageChanged()
        {
            if (RibbonControl != null)
                RibbonControl.Invalidate();
        }

        private void DrawRibbonLogo(Graphics graphics)
        {
            if (Image == null)
                return;
            RibbonViewInfo ribbonViewInfo = RibbonControl.ViewInfo;
            if (ribbonViewInfo == null)
                return;
            RibbonPanelViewInfo panelViewInfo = ribbonViewInfo.Panel;
            if (panelViewInfo == null)
                return;
            Rectangle bounds = panelViewInfo.Bounds;
            int minX = bounds.X;
            RibbonPageGroupViewInfoCollection groups = panelViewInfo.Groups;
            if (groups == null)
                return;
            if (groups.Count > 0)
                minX = groups[groups.Count - 1].Bounds.Right;
            if (bounds.Height < Image.Height)
                return;
            int offset = (bounds.Height - Image.Height) / 2;
            int width = Image.Width + 15;
            bounds.X = bounds.Width - width;
            if (bounds.X < minX)
                return;
            bounds.Width = width;
            bounds.Y += offset;
            bounds.Height = Image.Height;
            graphics.DrawImage(Image, bounds.Location);
        }
  
    }

最终达到自己想要效果的.

 技术分享图片

或者在标题栏上添加类似的Logo

DevExpress.XtraBars.Ribbon.ViewInfo.RibbonViewInfo ribbonViewInfo = ribbonControl1.ViewInfo;
            if (ribbonViewInfo == null)
                return;
            DevExpress.XtraBars.Ribbon.ViewInfo.RibbonCaptionViewInfo captionViewInfo = ribbonViewInfo.Caption;
            if (captionViewInfo == null)
                return;

            Rectangle bounds = new Rectangle(captionViewInfo.ContentBounds.X + 120, captionViewInfo.ContentBounds.Y, 
captionViewInfo.ContentBounds.Width - 22, captionViewInfo.ContentBounds.Height);
            Image image = DevExpress.Utils.Frames.ApplicationCaption8_1.GetImageLogoEx(LookAndFeel);

            e.Graphics.DrawImage(image, bounds.Location);

技术分享图片

Devexpress Ribbon Add Logo

标签:源代码   value   panel   count   ida   rms   wim   代码   designer   

原文地址:https://www.cnblogs.com/DoNetCShap/p/10274794.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!