示例#1
0
        /// <summary>
        /// Paints the Ribbon on the specified device
        /// </summary>
        /// <param name="g">Device where to paint on</param>
        /// <param name="clip">Clip rectangle</param>
        private void PaintOn(Graphics g, Rectangle clip)
        {
            if (WinApi.IsWindows && Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            }

            //Caption Background
            Renderer.OnRenderRibbonBackground(new RibbonRenderEventArgs(this, g, clip));

            //Caption Bar
            Renderer.OnRenderRibbonCaptionBar(new RibbonRenderEventArgs(this, g, clip));

            //Caption Buttons
            if (CaptionButtonsVisible)
            {
                MinimizeButton.OnPaint(this, new RibbonElementPaintEventArgs(clip, g, RibbonElementSizeMode.Medium));
                MaximizeRestoreButton.OnPaint(this, new RibbonElementPaintEventArgs(clip, g, RibbonElementSizeMode.Medium));
                CloseButton.OnPaint(this, new RibbonElementPaintEventArgs(clip, g, RibbonElementSizeMode.Medium));
            }

            //Orb
            Renderer.OnRenderRibbonOrb(new RibbonRenderEventArgs(this, g, clip));

            //QuickAcess toolbar
            QuickAcessToolbar.OnPaint(this, new RibbonElementPaintEventArgs(clip, g, RibbonElementSizeMode.Compact));

            //Render Tabs
            foreach (RibbonTab tab in Tabs)
            {
                tab.OnPaint(this, new RibbonElementPaintEventArgs(tab.TabBounds, g, RibbonElementSizeMode.None, this));
            }
        }
示例#2
0
        /// <summary>
        /// Overriden. Raises the Paint event and draws all the Ribbon content
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data.</param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (_updatingSuspended)
            {
                return;
            }

            if (Size != _lastSizeMeasured)
            {
                UpdateRegions(e.Graphics);
            }

            e.Graphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

            Renderer.OnRenderRibbonBackground(new RibbonRenderEventArgs(this, e.Graphics, e.ClipRectangle));

            //Caption Bar
            if (QuickAccessVisible)
            {
                Renderer.OnRenderRibbonCaptionBar(new RibbonRenderEventArgs(this, e.Graphics, e.ClipRectangle));
            }

            //Orb
            Renderer.OnRenderRibbonOrb(new RibbonRenderEventArgs(this, e.Graphics, e.ClipRectangle));

            //QuickAcess toolbar
            if (QuickAccessVisible)
            {
                QuickAcessToolbar.OnPaint(this, new RibbonElementPaintEventArgs(e.ClipRectangle, e.Graphics, RibbonElementSizeMode.Compact));
            }

            //Render Tabs
            foreach (RibbonTab tab in Tabs)
            {
                tab.OnPaint(this, new RibbonElementPaintEventArgs(tab.TabBounds, e.Graphics, RibbonElementSizeMode.None));
            }
        }
示例#3
0
文件: Ribbon.cs 项目: radtek/dms
        /// <summary>
        /// Updates the regions of the tabs and the tab content bounds of the active tab
        /// </summary>
        internal void UpdateRegions(Graphics g)
        {
            bool graphicsCreated = false;

            if (IsDisposed || _updatingSuspended)
            {
                return;
            }

            ///Graphics for measurement
            if (g == null)
            {
                g = CreateGraphics();
                graphicsCreated = true;
            }

            ///X coordinate reminder
            int curLeft = TabsMargin.Left + OrbBounds.Width;

            ///Saves the width of the larger tab
            int maxWidth = 0;

            ///Saves the bottom of the tabs
            int tabsBottom = 0;

            #region Assign default tab bounds (best case)
            foreach (RibbonTab tab in Tabs)
            {
                Size      tabSize = tab.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, RibbonElementSizeMode.None));
                Rectangle bounds  = new Rectangle(curLeft, TabsMargin.Top,
                                                  TabsPadding.Left + tabSize.Width + TabsPadding.Right,
                                                  TabsPadding.Top + tabSize.Height + TabsPadding.Bottom);

                tab.SetTabBounds(bounds);

                curLeft = bounds.Right + TabSpacing;

                maxWidth   = Math.Max(bounds.Width, maxWidth);
                tabsBottom = Math.Max(bounds.Bottom, tabsBottom);

                tab.SetTabContentBounds(Rectangle.FromLTRB(
                                            TabContentMargin.Left, tabsBottom + TabContentMargin.Top,
                                            ClientSize.Width - 1 - TabContentMargin.Right, ClientSize.Height - 1 - TabContentMargin.Bottom));

                if (tab.Active)
                {
                    tab.UpdatePanelsRegions();
                }
            }

            #endregion

            #region Reduce bounds of tabs if needed

            while (curLeft > ClientRectangle.Right && maxWidth > 0)
            {
                curLeft = TabsMargin.Left + OrbBounds.Width;
                maxWidth--;

                foreach (RibbonTab tab in Tabs)
                {
                    if (tab.TabBounds.Width >= maxWidth)
                    {
                        tab.SetTabBounds(new Rectangle(curLeft, TabsMargin.Top,
                                                       maxWidth, tab.TabBounds.Height));
                    }
                    else
                    {
                        tab.SetTabBounds(new Rectangle(
                                             new Point(curLeft, TabsMargin.Top),
                                             tab.TabBounds.Size));
                    }

                    curLeft = tab.TabBounds.Right + TabSpacing;
                }
            }

            #endregion

            #region Update QuickAccess bounds

            QuickAcessToolbar.MeasureSize(this, new RibbonElementMeasureSizeEventArgs(g, RibbonElementSizeMode.Compact));
            QuickAcessToolbar.SetBounds(new Rectangle(new Point(OrbBounds.Right + QuickAcessToolbar.Margin.Left, OrbBounds.Top - 2), QuickAcessToolbar.LastMeasuredSize));

            #endregion

            if (graphicsCreated)
            {
                g.Dispose();
            }

            _lastSizeMeasured = Size;
        }