RibbonContrl 画背景图片

Posted Jia_ShengJie

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RibbonContrl 画背景图片相关的知识,希望对你有一定的参考价值。

效果图如下:
具体代码如下:
 #region 设置标题栏背景图片
        //注册事件
         this.ribbonControl1.Paint += RibbonControl1_Paint;

        private void RibbonControl1_Paint(object sender, PaintEventArgs e)
        
            Image img = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + "image//welcome.png");
            DrawRibbonLogo(ribbonControl1, img, 0, e.Graphics);
        

        /// <summary>
        /// RibbonControl 画背景图(如果图片高度太大,会不美观)
        /// </summary>
        /// <param name="ribbonCtrl">RibbonControl 控件</param>
        /// <param name="img">图片</param>
        /// <param name="marginRight">居右间距</param>
        /// <param name="graphics">画布</param>
        private void DrawRibbonLogo(RibbonControl ribbonCtrl, Image img, int marginRight, Graphics graphics)
        
            RibbonViewInfo ribbonViewInfo = ribbonCtrl.ViewInfo;
            //page
            RibbonPanelViewInfo panelViewInfo = ribbonViewInfo.Panel;
            //group
            RibbonPageGroupViewInfoCollection groups = panelViewInfo.Groups;
            if (ribbonViewInfo == null || panelViewInfo == null || groups == null || groups.Count == 0)
                return;

            //Rectangle
            Rectangle bounds = panelViewInfo.Bounds;
            //x轴坐标最小值
            int minX = groups[groups.Count - 1].Bounds.Right;

            //取最小值作为宽度
            int width = Math.Min(bounds.Width - minX - 2, img.Width);
            int height = Math.Min(bounds.Height, img.Height);

            bounds.X = bounds.Width - width - marginRight;
            int addHeight = (bounds.Height - height) / 2;
            bounds.Y += addHeight - 2 > 0 ? addHeight - 2 : addHeight;

            bounds.Width = width;
            bounds.Height = height;

            graphics.DrawImage(img, bounds.Location);
        

        #endregion 设置标题栏背景图片

以上是关于RibbonContrl 画背景图片的主要内容,如果未能解决你的问题,请参考以下文章

字符的艺术——ASCII Art(附字符画大全)

cad间距怎么调整

CAD ML多线间距怎么设置?

Android如何改变TextView字体间距

RecyclerView 设置水平Item间距

背景图像部分之间的间距