Devexpress Ribbon Add Logo

  一直在網上找相似的效果.在Devpexress控件裏面的這個是一個Demo的.無法查看源代碼.也不知道怎麼寫的.因此就在網上搜索了半天的.post

 終於找到相似的解決辦法.spa

 能夠使用重繪製的辦法的來解決.code

[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);
        }
  
    }

最終達到本身想要效果的.orm

 

或者在標題欄上添加相似的Logoblog

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);

相關文章
相關標籤/搜索