示例#1
0
            static void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
            {
                var treeView = (TreeView)sender;

                try
                {
                    //Loosely based on Jason Williams solution (http://stackoverflow.com/questions/1003459/c-treeview-owner-drawing-with-ownerdrawtext-and-the-weird-black-highlighting-w)
                    if (e.Bounds.Height < 1 || e.Bounds.Width < 1)
                    {
                        return;
                    }

                    if (cIndentBy == -1)
                    {
                        cIndentBy = e.Bounds.Height;
                        cMargin   = e.Bounds.Height / 2;
                    }

                    Rectangle itemRect = e.Bounds;
                    e.Graphics.FillRectangle(Brushes.White, itemRect);
                    //e.Graphics.FillRectangle(Brushes.WhiteSmoke, itemRect);

                    int cTwoMargins = cMargin * 2;

                    int midY = (itemRect.Top + itemRect.Bottom) / 2;

                    int iconWidth     = itemRect.Height + 2;
                    int checkboxWidth = itemRect.Height + 2;

                    int indent       = (e.Node.Level * cIndentBy) + cMargin;
                    int iconLeft     = indent;                                     // lines left position
                    int checkboxLeft = iconLeft + iconWidth;                       // +/- icon left position

                    int textLeft = checkboxLeft + checkboxWidth;                   // text left position
                    if (!treeView.CheckBoxes)
                    {
                        textLeft = checkboxLeft;
                    }

                    // Draw parentage lines
                    if (treeView.ShowLines)
                    {
                        int x = cMargin * 2;

                        if (e.Node.Level == 0 && e.Node.PrevNode == null)
                        {
                            // The very first node in the tree has a half-height line
                            e.Graphics.DrawLine(dotPen, x, midY, x, itemRect.Bottom);
                        }
                        else
                        {
                            TreeNode testNode = e.Node;         // Used to only draw lines to nodes with Next Siblings, as in normal TreeViews
                            for (int iLine = e.Node.Level; iLine >= 0; iLine--)
                            {
                                if (testNode.NextNode != null)
                                {
                                    x = (iLine * cIndentBy) + (cMargin * 2);
                                    e.Graphics.DrawLine(dotPen, x, itemRect.Top, x, itemRect.Bottom);
                                }

                                testNode = testNode.Parent;
                            }

                            x = (e.Node.Level * cIndentBy) + (cMargin * 2);
                            e.Graphics.DrawLine(dotPen, x, itemRect.Top, x, midY);
                        }

                        e.Graphics.DrawLine(dotPen, iconLeft + cMargin, midY, iconLeft + cMargin + 10, midY);
                    }

                    // Draw (plus/minus) icon if required
                    if (e.Node.Nodes.Count > 0)
                    {
                        var element      = e.Node.IsExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                        var renderer     = new VisualStyleRenderer(element);
                        var iconTrueSize = renderer.GetPartSize(e.Graphics, ThemeSizeType.True);

                        var bounds = new Rectangle(itemRect.Left + iconLeft, itemRect.Top, iconWidth, iconWidth);

                        //e.Graphics.FillRectangle(Brushes.Salmon, bounds);

                        //deflate (resize and center) icon within bounds
                        var dif = (iconWidth - iconTrueSize.Height) / 2 - 1; //-1 is to compensate for rounding as icon is not getting rendered if the bounds is too small
                        bounds.Inflate(-dif, -dif);
                        renderer.DrawBackground(e.Graphics, bounds);
                    }

                    if (e.Node.IsReadOnly())
                    {
                        Debug.WriteLine($"Painting  {e.Node.Text}.Checked: {e.Node.Checked}");
                    }

                    //Checkbox
                    if (treeView.CheckBoxes)
                    {
                        var element = e.Node.Checked ? VisualStyleElement.Button.CheckBox.CheckedNormal : VisualStyleElement.Button.CheckBox.UncheckedNormal;
                        if (e.Node.IsReadOnly())
                        {
                            element = e.Node.Checked ? VisualStyleElement.Button.CheckBox.CheckedDisabled : VisualStyleElement.Button.CheckBox.UncheckedDisabled;
                        }

                        var renderer = new VisualStyleRenderer(element);
                        var bounds   = new Rectangle(itemRect.Left + checkboxLeft, itemRect.Top, checkboxWidth, itemRect.Height);
                        //e.Graphics.FillRectangle(Brushes.Bisque, bounds);
                        renderer.DrawBackground(e.Graphics, bounds);
                    }

                    //Text
                    if (!string.IsNullOrEmpty(e.Node.Text))
                    {
                        SizeF textSize = e.Graphics.MeasureString(e.Node.Text, treeView.Font);

                        var drawFormat = new StringFormat
                        {
                            Alignment     = StringAlignment.Near,
                            LineAlignment = StringAlignment.Center,
                            FormatFlags   = StringFormatFlags.NoWrap,
                        };

                        var bounds = new Rectangle(itemRect.Left + textLeft, itemRect.Top, (int)(textSize.Width + 2), itemRect.Height);

                        if (e.Node.IsSelected)
                        {
                            e.Graphics.FillRectangle(selectionModeBrush, bounds);
                            e.Graphics.DrawString(e.Node.Text, treeView.Font, Brushes.White, bounds, drawFormat);
                        }
                        else
                        {
                            var brush = Brushes.Black;
                            if (e.Node.IsReadOnly())
                            {
                                brush = Brushes.Gray;
                            }

                            e.Graphics.DrawString(e.Node.Text, treeView.Font, brush, bounds, drawFormat);
                        }
                    }

                    // Focus rectangle around the text
                    if (e.State == TreeNodeStates.Focused)
                    {
                        var r = itemRect;
                        r.Width  -= 2;
                        r.Height -= 2;
                        r.Offset(indent, 0);
                        r.Width -= indent;
                        e.Graphics.DrawRectangle(dotPen, r);
                    }
                }
                catch
                {
                    //The exception can be thrown in the result of incapability of the target OS.
                    //Thus users reported VisualStyleRenderer instantiation exception (https://wixsharp.codeplex.com/discussions/656266#)
                    //Thus fall back to more conservative rendering algorithm
                    treeView.DrawMode  = TreeViewDrawMode.OwnerDrawText;
                    treeView.DrawNode -= treeView_DrawNode;
                    treeView.DrawNode += treeView_DrawNodeText;
                }
            }
示例#2
0
        protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripSplitButton splitButton = e.Item as ToolStripSplitButton;
            Graphics             g           = e.Graphics;

            bool  rightToLeft = (splitButton.RightToLeft == RightToLeft.Yes);
            Color arrowColor  = splitButton.Enabled ? SystemColors.ControlText : SystemColors.ControlDark;

            // in right to left - we need to swap the parts so we dont draw  v][ toolStripSplitButton
            VisualStyleElement splitButtonDropDownPart = (rightToLeft) ? VisualStyleElement.ToolBar.SplitButton.Normal : VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
            VisualStyleElement splitButtonPart         = (rightToLeft) ? VisualStyleElement.ToolBar.DropDownButton.Normal : VisualStyleElement.ToolBar.SplitButton.Normal;

            Rectangle bounds = new Rectangle(Point.Empty, splitButton.Size);

            if (ToolStripManager.VisualStylesEnabled &&
                VisualStyleRenderer.IsElementDefined(splitButtonDropDownPart) &&
                VisualStyleRenderer.IsElementDefined(splitButtonPart))
            {
                VisualStyleRenderer vsRenderer = VisualStyleRenderer;

                // Draw the SplitButton Button portion of it.
                vsRenderer.SetParameters(splitButtonPart.ClassName, splitButtonPart.Part, GetSplitButtonItemState(splitButton));

                // the lovely Windows theming for split button comes in three pieces:
                //  SplitButtonDropDown: [ v |
                //  Separator:                |
                //  SplitButton:               |  ]
                // this is great except if you want to swap the button in RTL.  In this case we need
                // to use the DropDownButton instead of the SplitButtonDropDown and paint the arrow ourselves.
                Rectangle splitButtonBounds = splitButton.ButtonBounds;
                if (rightToLeft)
                {
                    // scoot to the left so we dont draw double shadow like so: ][
                    splitButtonBounds.Inflate(2, 0);
                }

                // Draw the button portion of it.
                vsRenderer.DrawBackground(g, splitButtonBounds);

                // Draw the SplitButton DropDownButton portion of it.
                vsRenderer.SetParameters(splitButtonDropDownPart.ClassName, splitButtonDropDownPart.Part, GetSplitButtonDropDownItemState(splitButton));

                // Draw the drop down button portion
                vsRenderer.DrawBackground(g, splitButton.DropDownButtonBounds);

                // fill in the background image
                Rectangle fillRect = splitButton.ContentRectangle;
                if (splitButton.BackgroundImage is not null)
                {
                    ControlPaint.DrawBackgroundImage(g, splitButton.BackgroundImage, splitButton.BackColor, splitButton.BackgroundImageLayout, fillRect, fillRect);
                }

                // draw the separator over it.
                RenderSeparatorInternal(g, splitButton, splitButton.SplitterBounds, true);

                // and of course, now if we're in RTL we now need to paint the arrow
                // because we're no longer using a part that has it built in.
                if (rightToLeft || splitButton.BackgroundImage is not null)
                {
                    DrawArrow(new ToolStripArrowRenderEventArgs(g, splitButton, splitButton.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                }
            }
            else
            {
                // Draw the split button button
                Rectangle splitButtonButtonRect = splitButton.ButtonBounds;

                if (splitButton.BackgroundImage is not null)
                {
                    // fill in the background image
                    Rectangle fillRect = (splitButton.Selected) ? splitButton.ContentRectangle : bounds;
                    if (splitButton.BackgroundImage is not null)
                    {
                        ControlPaint.DrawBackgroundImage(g, splitButton.BackgroundImage, splitButton.BackColor, splitButton.BackgroundImageLayout, bounds, fillRect);
                    }
                }
                else
                {
                    FillBackground(g, splitButtonButtonRect, splitButton.BackColor);
                }

                ToolBarState state = GetSplitButtonToolBarState(splitButton, false);

                RenderSmall3DBorderInternal(g, splitButtonButtonRect, state, rightToLeft);

                // draw the split button drop down
                Rectangle dropDownRect = splitButton.DropDownButtonBounds;

                // fill the color in the dropdown button
                if (splitButton.BackgroundImage is null)
                {
                    FillBackground(g, dropDownRect, splitButton.BackColor);
                }

                state = GetSplitButtonToolBarState(splitButton, true);

                if ((state == ToolBarState.Pressed) || (state == ToolBarState.Hot))
                {
                    RenderSmall3DBorderInternal(g, dropDownRect, state, rightToLeft);
                }

                DrawArrow(new ToolStripArrowRenderEventArgs(g, splitButton, dropDownRect, arrowColor, ArrowDirection.Down));
            }
        }
示例#3
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            Graphics       g    = e.Graphics;
            TabStrip       tabs = e.ToolStrip as TabStrip;
            TabStripButton tab  = e.Item as TabStripButton;

            if (tabs == null || tab == null)
            {
                if (currentRenderer != null)
                {
                    currentRenderer.DrawButtonBackground(e);
                }
                else
                {
                    base.OnRenderButtonBackground(e);
                }
                return;
            }

            bool      selected = tab.Checked;
            bool      hovered  = tab.Selected;
            int       top      = 0;
            int       left     = 0;
            int       width    = tab.Bounds.Width - 1;
            int       height   = tab.Bounds.Height - 1;
            Rectangle drawBorder;


            if (UseVS)
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    drawBorder = new Rectangle(0, 0, width, height);
                }
                else
                {
                    if (!selected)
                    {
                        left   = selOffset;
                        width -= (selOffset - 1);
                    }
                    else
                    {
                        left = 1;
                    }
                    drawBorder = new Rectangle(0, 0, height, width);
                }
                using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height))
                {
                    VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal;
                    if (selected)
                    {
                        el = VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (hovered)
                    {
                        el = VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!tab.Enabled)
                    {
                        el = VisualStyleElement.Tab.TabItem.Disabled;
                    }

                    if (!selected || hovered)
                    {
                        drawBorder.Width++;
                    }
                    else
                    {
                        drawBorder.Height++;
                    }

                    using (Graphics gr = Graphics.FromImage(b))
                    {
                        VisualStyleRenderer rndr = new VisualStyleRenderer(el);
                        rndr.DrawBackground(gr, drawBorder);

                        if (tabs.Orientation == Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipXY);
                            }
                            else
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            }
                        }
                        if (Mirrored)
                        {
                            left = tab.Bounds.Width - b.Width - left;
                            top  = tab.Bounds.Height - b.Height - top;
                        }
                        g.DrawImage(b, left, top);
                    }
                }
            }
            else
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    if (Mirrored)
                    {
                        left = 1;
                        top  = 0;
                    }
                    else
                    {
                        top++;
                    }
                    width--;
                }
                else
                {
                    if (!selected)
                    {
                        left = selOffset;
                        width--;
                    }
                    else
                    {
                        left = 1;
                    }
                    if (Mirrored)
                    {
                        left = 0;
                        top  = 1;
                    }
                }
                height--;
                drawBorder = new Rectangle(left, top, width, height);

                using (GraphicsPath gp = new GraphicsPath())
                {
                    if (Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top);
                    }
                    else if (!Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom);
                    }
                    else if (Mirrored && tabs.Orientation == Orientation.Vertical)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom);
                    }
                    else
                    {
                        gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom);
                    }

                    if (selected || hovered)
                    {
                        Color fill = (hovered) ? Color.WhiteSmoke : Color.White;
                        if (renderMode == ToolStripRenderMode.Professional)
                        {
                            fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd;
                            using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical))
                                g.FillPath(br, gp);
                        }
                        else
                        {
                            using (SolidBrush br = new SolidBrush(fill))
                                g.FillPath(br, gp);
                        }
                    }
                    using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace))
                        g.DrawPath(p, gp);
                }
            }
        }
示例#4
0
        public static void DrawCheckBox(Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, CheckBoxState state)
        {
            Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));

            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr = GetCheckBoxRenderer(state);

                vsr.DrawBackground(g, bounds);

                if (image != null)
                {
                    vsr.DrawImage(g, imageBounds, image);
                }

                if (focused)
                {
                    ControlPaint.DrawFocusRectangle(g, textBounds);
                }

                if (checkBoxText != String.Empty)
                {
                    if (state == CheckBoxState.CheckedDisabled || state == CheckBoxState.MixedDisabled || state == CheckBoxState.UncheckedDisabled)
                    {
                        TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.GrayText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.ControlText, flags);
                    }
                }
            }
            else
            {
                switch (state)
                {
                case CheckBoxState.CheckedDisabled:
                case CheckBoxState.MixedDisabled:
                case CheckBoxState.MixedPressed:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Inactive | ButtonState.Checked);
                    break;

                case CheckBoxState.CheckedHot:
                case CheckBoxState.CheckedNormal:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Checked);
                    break;

                case CheckBoxState.CheckedPressed:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Pushed | ButtonState.Checked);
                    break;

                case CheckBoxState.MixedHot:
                case CheckBoxState.MixedNormal:
                    ControlPaint.DrawMixedCheckBox(g, bounds, ButtonState.Checked);
                    break;

                case CheckBoxState.UncheckedDisabled:
                case CheckBoxState.UncheckedPressed:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Inactive);
                    break;

                case CheckBoxState.UncheckedHot:
                case CheckBoxState.UncheckedNormal:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Normal);
                    break;
                }

                if (image != null)
                {
                    g.DrawImage(image, imageBounds);
                }

                if (focused)
                {
                    ControlPaint.DrawFocusRectangle(g, textBounds);
                }

                if (checkBoxText != String.Empty)
                {
                    TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.ControlText, flags);
                }
            }
        }
        /// <summary>
        /// Gets the background image of the current visual style element within the specified background color. If <paramref name="states"/> is set, the resulting image will contain each of the state images side by side.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
        /// <param name="clr">The background color. This color cannot have an alpha channel.</param>
        /// <param name="states">The optional list of states to render side by side.</param>
        /// <returns>The background image.</returns>
        public static Bitmap GetBackgroundBitmap(this VisualStyleRenderer rnd, Color clr, int[] states = null)
        {
            const int wh = 200;

            if (rnd == null)
            {
                throw new ArgumentNullException(nameof(rnd));
            }
            rnd.SetParameters(rnd.Class, rnd.Part, 0);
            if (states == null || states.Length == 0)
            {
                states = new[] { rnd.State }
            }
            ;
            var i = states.Length;

            // Get image size
            Size imgSz;

            using (var sg = Graphics.FromHwnd(IntPtr.Zero))
                imgSz = rnd.GetPartSize(sg, new Rectangle(0, 0, wh, wh), ThemeSizeType.Draw);
            if (imgSz.Width == 0 || imgSz.Height == 0)
            {
                imgSz = new Size(rnd.GetInteger(IntegerProperty.Width), rnd.GetInteger(IntegerProperty.Height));
            }
            if (imgSz.Width == 0 || imgSz.Height == 0)
            {
                using (var sg = Graphics.FromHwnd(IntPtr.Zero))
                    imgSz = MaxSize(rnd.GetPartSize(sg, new Rectangle(0, 0, wh, wh), ThemeSizeType.Minimum), imgSz);
            }

            var bounds = new Rectangle(0, 0, imgSz.Width * i, imgSz.Height);

            // Draw each background linearly down the bitmap
            using (var memoryHdc = SafeDCHandle.ScreenCompatibleDCHandle)
            {
                // Create a device-independent bitmap and select it into our DC
                var    info = new BITMAPINFO(bounds.Width, -bounds.Height);
                IntPtr ppv;
                using (new SafeDCObjectHandle(memoryHdc, CreateDIBSection(SafeDCHandle.Null, ref info, DIBColorMode.DIB_RGB_COLORS, out ppv, IntPtr.Zero, 0)))
                {
                    using (var memoryGraphics = Graphics.FromHdc(memoryHdc.DangerousGetHandle()))
                    {
                        // Setup graphics
                        memoryGraphics.CompositingMode    = CompositingMode.SourceOver;
                        memoryGraphics.CompositingQuality = CompositingQuality.HighQuality;
                        memoryGraphics.SmoothingMode      = SmoothingMode.HighQuality;
                        memoryGraphics.Clear(clr);

                        // Draw each background linearly down the bitmap
                        var rect = new Rectangle(0, 0, imgSz.Width, imgSz.Height);
                        foreach (var state in states)
                        {
                            rnd.SetParameters(rnd.Class, rnd.Part, state);
                            rnd.DrawBackground(memoryGraphics, rect);
                            rect.X += imgSz.Width;
                        }
                    }

                    // Copy DIB to Bitmap
                    var bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
                    using (var primaryHdc = new SafeDCHandle(Graphics.FromImage(bmp)))
                        BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, RasterOperationMode.SRCCOPY);
                    return(bmp);
                }
            }
        }
示例#6
0
        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
        public static void DrawHorizontalTrack(Graphics g, Rectangle bounds)
        {
            InitializeRenderer(VisualStyleElement.TrackBar.Track.Normal, 1);

            visualStyleRenderer.DrawBackground(g, bounds);
        }
示例#7
0
        [SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] // Using Graphics instead of IDeviceContext intentionally
        public static void DrawArrowButton(Graphics g, Rectangle bounds, ScrollBarArrowButtonState state)
        {
            InitializeRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftNormal, (int)state);

            visualStyleRenderer.DrawBackground(g, bounds);
        }
示例#8
0
        public override void DrawDayHeader(System.Drawing.Graphics g, System.Drawing.Rectangle rect, DateTime date)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            // Header background
            bool isToday = date.Date.Equals(DateTime.Now.Date);

            Rectangle rHeader = rect;

            rHeader.X++;

            if (VisualStyleRenderer.IsSupported)
            {
                bool hasTodayColor = Theme.HasAppColor(UITheme.AppColor.Today);
                var  headerState   = VisualStyleElement.Header.Item.Normal;

                if (isToday && !hasTodayColor)
                {
                    headerState = VisualStyleElement.Header.Item.Hot;
                }

                var renderer = new VisualStyleRenderer(headerState);
                renderer.DrawBackground(g, rHeader);

                if (isToday && hasTodayColor)
                {
                    rHeader.X--;

                    using (var brush = new SolidBrush(Theme.GetAppDrawingColor(UITheme.AppColor.Today, 64)))
                        g.FillRectangle(brush, rHeader);
                }
            }
            else             // classic theme
            {
                rHeader.Y++;

                var headerBrush = (isToday ? SystemBrushes.ButtonHighlight : SystemBrushes.ButtonFace);
                g.FillRectangle(headerBrush, rHeader);

                ControlPaint.DrawBorder3D(g, rHeader, Border3DStyle.Raised);
            }

            // Header text
            using (StringFormat format = new StringFormat())
            {
                format.Alignment     = StringAlignment.Center;
                format.FormatFlags   = StringFormatFlags.NoWrap;
                format.LineAlignment = StringAlignment.Center;

                using (StringFormat formatdd = new StringFormat())
                {
                    formatdd.Alignment     = StringAlignment.Near;
                    formatdd.FormatFlags   = StringFormatFlags.NoWrap;
                    formatdd.LineAlignment = StringAlignment.Center;

                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

                    // Day of month
                    using (Font fntDayDate = new Font("Tahoma", 9, FontStyle.Bold))
                    {
                        var dateNum = date.ToString(" d");
                        g.DrawString(dateNum, fntDayDate, SystemBrushes.WindowText, rect, formatdd);

                        int strWidth = (int)g.MeasureString(dateNum, fntDayDate).Width;

                        rect.Width -= strWidth;
                        rect.X     += strWidth;
                    }

                    // Day of week
                    using (Font fntDay = new Font("Tahoma", 8, FontStyle.Regular))
                    {
                        string dayName   = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(date.DayOfWeek);
                        int    nameWidth = (int)g.MeasureString(dayName, fntDay).Width;

                        // get short day abbr. if narrow dayrect
                        if (rect.Width < nameWidth)
                        {
                            dayName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
                        }

                        TextRenderer.DrawText(g, dayName, fntDay, rect, SystemColors.WindowText);
                        //g.DrawString(dayName, fntDay, SystemBrushes.WindowText, rect, format);
                    }
                }
            }
        }
        // This redraws the tabs
        protected unsafe void RedrawTabs()
        {
            // Determine length and width in pixels
            int tabslength = 0;

            for (int i = 0; i < this.TabPages.Count; i++)
            {
                Rectangle r = this.GetTabRect(i);
                tabslength += r.Height;
            }
            tabslength += 4;
            int tabswidth = this.ItemSize.Height + 2;

            // Dispose old image
            if (tabsimage != null)
            {
                tabsimage.Dispose();
                tabsimage = null;
            }

            if (VisualStyleInformation.IsSupportedByOS && VisualStyleInformation.IsEnabledByUser)
            {
                StringFormat drawformat = new StringFormat();
                drawformat.Alignment     = StringAlignment.Center;
                drawformat.HotkeyPrefix  = HotkeyPrefix.None;
                drawformat.LineAlignment = StringAlignment.Center;

                // Create images
                tabsimage = new Bitmap(tabswidth, tabslength, PixelFormat.Format32bppArgb);
                Bitmap   drawimage = new Bitmap(tabslength, tabswidth, PixelFormat.Format32bppArgb);
                Graphics g         = Graphics.FromImage(drawimage);

                // Render the tabs (backwards when right-aligned)
                int posoffset         = 0;
                int selectedposoffset = -1;
                int start             = (this.Alignment == TabAlignment.Left) ? 0 : (this.TabPages.Count - 1);
                int end  = (this.Alignment == TabAlignment.Left) ? this.TabPages.Count : -1;
                int step = (this.Alignment == TabAlignment.Left) ? 1 : -1;
                for (int i = start; i != end; i += step)
                {
                    VisualStyleRenderer renderer;
                    Rectangle           tr = this.GetTabRect(i);

                    // Tab selected?
                    if (i == this.SelectedIndex)
                    {
                        // We will draw this later
                        selectedposoffset = posoffset;
                    }
                    else
                    {
                        if (i == highlighttab)
                        {
                            renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot);
                        }
                        else
                        {
                            renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
                        }

                        // Draw tab
                        Rectangle r = new Rectangle(posoffset + 2, 2, tr.Height, tr.Width - 2);
                        renderer.DrawBackground(g, r);
                        g.DrawString(this.TabPages[i].Text, this.Font, SystemBrushes.ControlText, new RectangleF(r.Location, r.Size), drawformat);
                    }

                    posoffset += tr.Height;
                }

                // Render the selected tab, because it is slightly larger and overlapping the others
                if (selectedposoffset > -1)
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed);
                    Rectangle           tr       = this.GetTabRect(this.SelectedIndex);
                    Rectangle           r        = new Rectangle(selectedposoffset, 0, tr.Height + 4, tr.Width);
                    renderer.DrawBackground(g, r);
                    g.DrawString(this.TabPages[this.SelectedIndex].Text, this.Font, SystemBrushes.ControlText, new RectangleF(r.X, r.Y, r.Width, r.Height - 2), drawformat);
                }

                // Rotate the image and copy to tabsimage
                BitmapData drawndata  = drawimage.LockBits(new Rectangle(0, 0, drawimage.Size.Width, drawimage.Size.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                BitmapData targetdata = tabsimage.LockBits(new Rectangle(0, 0, tabsimage.Size.Width, tabsimage.Size.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                int *      dd         = (int *)drawndata.Scan0.ToPointer();
                int *      td         = (int *)targetdata.Scan0.ToPointer();
                if (this.Alignment == TabAlignment.Right)
                {
                    for (int y = 0; y < drawndata.Height; y++)
                    {
                        for (int x = 0; x < drawndata.Width; x++)
                        {
                            td[(drawndata.Width - 1 - x) * targetdata.Width + y] = *dd;
                            dd++;
                        }
                    }
                }
                else
                {
                    for (int y = 0; y < drawndata.Height; y++)
                    {
                        for (int x = 0; x < drawndata.Width; x++)
                        {
                            td[x * targetdata.Width + (drawndata.Height - 1 - y)] = *dd;
                            dd++;
                        }
                    }
                }
                drawimage.UnlockBits(drawndata);
                tabsimage.UnlockBits(targetdata);

                // Clean up
                g.Dispose();
                drawimage.Dispose();
            }
        }
示例#10
0
        /// <summary>
        /// Generates a bitmap to display beside the ToolStripItem representation of the specified node.
        /// </summary>
        /// <param name="bitmapInfo"></param>
        /// <param name="nodeImage"></param>
        /// <returns></returns>
        private Image GenerateBitmap(BitmapInfo bitmapInfo, Image nodeImage)
        {
            int indentation = INDENT_WIDTH * bitmapInfo.NodeDepth;
            int halfIndent  = INDENT_WIDTH / 2;
            int halfHeight  = itemHeight / 2;

            // create a bitmap that will be composed of the node's image and the glyphs/lines/indentation
            Bitmap   composite = new Bitmap(INDENT_WIDTH + indentation + ((nodeImage != null) ? nodeImage.Width : 0), itemHeight);
            Graphics g         = Graphics.FromImage(composite);

            Pen dotted = new Pen(Color.Gray);

            dotted.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

            // horizontal dotted line
            g.DrawLine(dotted, indentation + halfIndent, halfHeight, indentation + INDENT_WIDTH, halfHeight);

            // vertical dotted line to peers
            g.DrawLine(dotted, indentation + halfIndent, bitmapInfo.IsFirst ? halfHeight : 0, indentation + halfIndent, bitmapInfo.IsLastPeer ? halfHeight : itemHeight);

            // vertical dotted line to subtree
            if (bitmapInfo.NodeExpanded)
            {
                g.DrawLine(dotted, INDENT_WIDTH + indentation + halfIndent, halfHeight, INDENT_WIDTH + indentation + halfIndent, itemHeight);
            }

            // outer vertical dotted lines
            for (int i = 0; i < bitmapInfo.VerticalLines.Length; i++)
            {
                if (bitmapInfo.VerticalLines[i])
                {
                    int parentIndent = (INDENT_WIDTH * (bitmapInfo.NodeDepth - (i + 1)));
                    g.DrawLine(dotted, parentIndent + halfIndent, 0, parentIndent + halfIndent, itemHeight);
                }
            }

            // composite the image associated with node (appears at far right)
            if (nodeImage != null)
            {
                g.DrawImage(nodeImage, new Rectangle(
                                INDENT_WIDTH + indentation,
                                composite.Height / 2 - nodeImage.Height / 2,
                                nodeImage.Width,
                                nodeImage.Height
                                ));
            }

            // render plus/minus glyphs
            if (bitmapInfo.HasChildren)
            {
                Rectangle          glyphBounds = new Rectangle(indentation, composite.Height / 2 - GLYPH_SIZE / 2, GLYPH_SIZE, GLYPH_SIZE);
                VisualStyleElement elem        = bitmapInfo.NodeExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;

                if (sourceControl.DrawWithVisualStyles && VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(elem))
                {
                    // visual style support, render using visual styles
                    VisualStyleRenderer r = new VisualStyleRenderer(elem);
                    r.DrawBackground(g, glyphBounds);
                }
                else
                {
                    // no visual style support, render using bitmap
                    Image glyph = bitmapInfo.NodeExpanded ? Expanded : Collapsed;
                    g.DrawImage(glyph, glyphBounds);
                }
            }

            return(composite);
        }
示例#11
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode != null)
            {
                Graphics g = Graphics.FromHwnd(this.Handle);
                g.Clear(this.BackColor);
                TextY = 0;

                if (VisualStyleInformation.IsSupportedByOS)
                {
                    DrawText(g, "VisualStyles supported by OS");
                }
                else
                {
                    DrawText(g, "VisualStyles not supported by OS.");
                    return;
                }

                if (VisualStyleInformation.IsEnabledByUser)
                {
                    DrawText(g, "VisualStyles enabled by user.");
                }
                else
                {
                    DrawText(g, "VisualStyles not enabled by user.");
                    return;
                }

                // Create the VisualStyleElement
                MethodInfo         m   = (MethodInfo)treeView1.SelectedNode.Tag;
                VisualStyleElement vse = (VisualStyleElement)m.Invoke(null, null);

                if (!VisualStyleRenderer.IsElementDefined(vse))
                {
                    DrawText(g, treeView1.SelectedNode.Text + " is not defined by the current style.");
                    return;
                }

                try {
                    // Create the VisualStyleRenderer
                    if (vsr == null)
                    {
                        vsr = new VisualStyleRenderer(vse);
                    }
                    else
                    {
                        vsr.SetParameters(vse);
                    }

                    // Draw some pretty graphics
                    TextY += 25;
                    vsr.DrawBackground(g, new Rectangle(250, TextY, 25, 25));
                    vsr.DrawBackground(g, new Rectangle(350, TextY, 50, 50));
                    vsr.DrawBackground(g, new Rectangle(450, TextY, 50, 50), new Rectangle(450, TextY, 25, 25));
                    TextY += 75;

                    // Test some other methods
                    DrawText(g, "GetBackgroundContentRectangle: " + vsr.GetBackgroundContentRectangle(g, new Rectangle(300, 0, 300, 50)).ToString());
                    DrawText(g, "GetBackgroundExtent: " + vsr.GetBackgroundExtent(g, new Rectangle(300, 0, 300, 50)).ToString());
                    DrawText(g, "GetBoolean: " + vsr.GetBoolean(BooleanProperty.MirrorImage).ToString());
                    DrawText(g, "GetEnumValue: " + vsr.GetEnumValue(EnumProperty.VerticalAlignment).ToString());
                    DrawText(g, "GetFilename: " + vsr.GetFilename(FilenameProperty.ImageFile).ToString());
                    DrawText(g, "GetInteger: " + vsr.GetInteger(IntegerProperty.BorderSize).ToString());
                    DrawText(g, "GetMargins: " + vsr.GetMargins(g, MarginProperty.CaptionMargins).ToString());
                    DrawText(g, "GetPartSize: " + vsr.GetPartSize(g, ThemeSizeType.Draw).ToString());
                    DrawText(g, "GetPoint: " + vsr.GetPoint(PointProperty.MinSize).ToString());
                    DrawText(g, "GetString: " + vsr.GetString(StringProperty.Text).ToString());
                    DrawText(g, "GetTextExtent: " + vsr.GetTextExtent(g, "HeyThere!", TextFormatFlags.Default).ToString());
                    DrawText(g, "GetTextMetrics: " + vsr.GetTextMetrics(g).Ascent.ToString());
                    DrawText(g, "GetBackgroundRegion: " + vsr.GetBackgroundRegion(g, this.ClientRectangle).GetBounds(g).ToString());
                    DrawText(g, "HitTestBackground: " + vsr.HitTestBackground(g, this.ClientRectangle, new Point(300, 300), HitTestOptions.Caption).ToString());
                    DrawText(g, "Author: " + VisualStyleInformation.Author);
                    DrawText(g, "ColorScheme: " + VisualStyleInformation.ColorScheme);
                    DrawText(g, "Company: " + VisualStyleInformation.Company);
                    DrawText(g, "ControlHighlightHot: " + VisualStyleInformation.ControlHighlightHot.ToString());
                    DrawText(g, "Copyright: " + VisualStyleInformation.Copyright);
                    DrawText(g, "Description: " + VisualStyleInformation.Description);
                    DrawText(g, "DisplayName: " + VisualStyleInformation.DisplayName);
                    DrawText(g, "MinimumColorDepth: " + VisualStyleInformation.MinimumColorDepth.ToString());
                    DrawText(g, "Size: " + VisualStyleInformation.Size.ToString());
                    DrawText(g, "SupportsFlatMenus: " + VisualStyleInformation.SupportsFlatMenus.ToString());
                    DrawText(g, "TextControlBorder: " + VisualStyleInformation.TextControlBorder.ToString());
                    DrawText(g, "Url: " + VisualStyleInformation.Url);
                    DrawText(g, "Version: " + VisualStyleInformation.Version.ToString());
                }
                catch (Exception ex) {
                    System.Console.WriteLine(ex.ToString());
                }
            }
        }
示例#12
0
        /// <summary>
        ///  Renders a Tab item.
        /// </summary>
        public static void DrawTabItem(Graphics g, Rectangle bounds, TabItemState state)
        {
            InitializeRenderer(VisualStyleElement.Tab.TabItem.Normal, (int)state);

            visualStyleRenderer.DrawBackground(g, bounds);
        }
示例#13
0
        public static void DrawHorizontalBar(Graphics g, Rectangle bounds)
        {
            InitializeRenderer(VisualStyleElement.ProgressBar.Bar.Normal);

            visualStyleRenderer.DrawBackground(g, bounds);
        }
示例#14
0
        private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = false;
            Rectangle rect = e.Bounds;

            if (rect.Height == 0)
            {
                ///在展开节点的时候会出现根节点绘制错误的问题
                return;
            }
            if ((e.State & TreeNodeStates.Selected) != 0)
            {
                if ((e.State & TreeNodeStates.Focused) != 0)
                {
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, rect);
                }
                else
                {
                    e.Graphics.FillRectangle(SystemBrushes.Control, rect);
                }
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, rect);
            }
            int IndentWidth = DatatreeView.Indent * e.Node.Level + 25;

            e.Graphics.DrawRectangle(SystemPens.Control, rect);
            Rectangle StringRect = new Rectangle(e.Bounds.X + IndentWidth, e.Bounds.Y, colName.Width - IndentWidth, e.Bounds.Height);

            String TreeNameString = e.Node.Text;

            if (TreeNameString.EndsWith(MongoDBHelper.Array_Mark))
            {
                //Array_Mark 在计算路径的时候使用,不过,在表示的时候,则不能表示
                TreeNameString = TreeNameString.Substring(0, TreeNameString.Length - MongoDBHelper.Array_Mark.Length);
            }
            if (TreeNameString.EndsWith(MongoDBHelper.Document_Mark))
            {
                //Document_Mark 在计算路径的时候使用,不过,在表示的时候,则不能表示
                TreeNameString = TreeNameString.Substring(0, TreeNameString.Length - MongoDBHelper.Document_Mark.Length);
            }
            //感谢cyrus的建议,选中节点的文字表示,底色变更
            if ((e.State & TreeNodeStates.Selected) != 0 && (e.State & TreeNodeStates.Focused) != 0)
            {
                e.Graphics.DrawString(TreeNameString, this.Font, new SolidBrush(SystemColors.HighlightText), StringRect);
            }
            else
            {
                e.Graphics.DrawString(TreeNameString, this.Font, new SolidBrush(Color.Black), StringRect);
            }

            BsonElement mElement = e.Node.Tag as BsonElement;
            BsonValue   mValue   = e.Node.Tag as BsonValue;

            //画框
            if (e.Node.GetNodeCount(true) > 0 || (mElement != null && (mElement.Value.IsBsonDocument || mElement.Value.IsBsonArray)))
            {
                //感谢Cyrus测试出来的问题:RenderWithVisualStyles应该加上去的。
                if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
                {
                    int LeftPoint = e.Bounds.X + IndentWidth - 20;
                    //感谢 Shadower http://home.cnblogs.com/u/14697/ 贡献的代码
                    var thisNode = e.Node;
                    var glyph    = thisNode.IsExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                    var vsr      = new VisualStyleRenderer(glyph);
                    vsr.DrawBackground(e.Graphics, new Rectangle(LeftPoint, e.Bounds.Y + 4, 16, 16));
                }
                else
                {
                    int LeftPoint = e.Bounds.X + IndentWidth - 20;
                    e.Graphics.DrawRectangle(new Pen(Color.Black), new Rectangle(LeftPoint, e.Bounds.Y + 4, 12, 12));
                    Point LeftMid   = new Point(LeftPoint + 2, e.Bounds.Y + 10);
                    Point RightMid  = new Point(LeftPoint + 10, e.Bounds.Y + 10);
                    Point TopMid    = new Point(LeftPoint + 6, e.Bounds.Y + 6);
                    Point BottomMid = new Point(LeftPoint + 6, e.Bounds.Y + 14);
                    e.Graphics.DrawLine(new Pen(Color.Black), LeftMid, RightMid);
                    if (!e.Node.IsExpanded)
                    {
                        e.Graphics.DrawLine(new Pen(Color.Black), TopMid, BottomMid);
                    }
                }
            }

            for (int intColumn = 1; intColumn < 3; intColumn++)
            {
                rect.Offset(this.listView.Columns[intColumn - 1].Width, 0);
                rect.Width = this.listView.Columns[intColumn].Width;
                e.Graphics.DrawRectangle(SystemPens.Control, rect);
                if (mElement != null || mValue != null)
                {
                    string strColumnText = String.Empty;
                    if (intColumn == 1)
                    {
                        if (mElement != null)
                        {
                            if (!mElement.Value.IsBsonDocument && !mElement.Value.IsBsonArray)
                            {
                                strColumnText = mElement.Value.ToString();
                            }
                        }
                        else
                        {
                            if (mValue != null)
                            {
                                if (!mValue.IsBsonDocument && !mValue.IsBsonArray)
                                {
                                    if (e.Node.Level > 0)
                                    {
                                        //根节点有Value,可能是ID,用来取得选中节点的信息
                                        strColumnText = mValue.ToString();
                                    }
                                }
                                //Type这里已经有表示Type的标识了,这里就不重复显示了。
                                //else
                                //{
                                //if (mValue.IsBsonDocument) { strColumnText = MongoDBHelper.Document_Mark; }
                                //if (mValue.IsBsonArray) { strColumnText = MongoDBHelper.Array_Mark; }
                                //}
                            }
                        }
                    }
                    else
                    {
                        if (mElement != null)
                        {
                            strColumnText = mElement.Value.GetType().Name.Substring(4);
                        }
                        else
                        {
                            strColumnText = mValue.GetType().Name.Substring(4);
                        }
                    }

                    TextFormatFlags flags = TextFormatFlags.EndEllipsis;
                    switch (this.listView.Columns[intColumn].TextAlign)
                    {
                    case HorizontalAlignment.Center:
                        flags |= TextFormatFlags.HorizontalCenter;
                        break;

                    case HorizontalAlignment.Left:
                        flags |= TextFormatFlags.Left;
                        break;

                    case HorizontalAlignment.Right:
                        flags |= TextFormatFlags.Right;
                        break;

                    default:
                        break;
                    }

                    rect.Y++;
                    if ((e.State & TreeNodeStates.Selected) != 0 &&
                        (e.State & TreeNodeStates.Focused) != 0)
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, SystemColors.HighlightText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, e.Node.ForeColor, e.Node.BackColor, flags);
                    }
                    rect.Y--;
                }
            }
        }
示例#15
0
        /// <summary>
        /// Draw one cell of the header
        /// </summary>
        /// <param name="g"></param>
        /// <param name="columnIndex"></param>
        /// <param name="itemState"></param>
        protected void CustomDrawHeaderCell(Graphics g, int columnIndex, int itemState)
        {
            // TODO: This needs to be refactored
            const int CDIS_SELECTED     = 1;
            Rectangle r                 = this.GetItemRect(columnIndex);
            OLVColumn column            = this.ListView.GetColumn(columnIndex);
            int       columnUnderCursor = this.ColumnIndexUnderCursor;

            // Draw the background
            if (VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.Item.Normal))
            {
                int part = 1; // normal item
                if (columnIndex == 0 &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemLeft.Normal))
                {
                    part = 2; // left item
                }
                if (columnIndex == this.ListView.Columns.Count - 1 &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.ItemRight.Normal))
                {
                    part = 3;  // right item
                }
                int state = 1; // normal state
                if ((itemState & CDIS_SELECTED) == CDIS_SELECTED)
                {
                    state = 3; // pressed
                }
                else if (columnIndex == this.ColumnIndexUnderCursor)
                {
                    state = 2; // hot
                }
                VisualStyleRenderer renderer = new VisualStyleRenderer("HEADER", part, state);
                renderer.DrawBackground(g, r);
            }
            else
            {
                //g.FillRectangle(Brushes.LightGray, r);
                ControlPaint.DrawBorder3D(g, r, Border3DStyle.Raised);
            }

            // Draw the sort indicator if this column has one
            if (this.HasSortIndicator(column))
            {
                if (VisualStyleRenderer.IsSupported &&
                    VisualStyleRenderer.IsElementDefined(VisualStyleElement.Header.SortArrow.SortedUp))
                {
                    VisualStyleRenderer renderer2 = null;
                    if (this.ListView.LastSortOrder == SortOrder.Ascending)
                    {
                        renderer2 = new VisualStyleRenderer(VisualStyleElement.Header.SortArrow.SortedUp);
                    }
                    if (this.ListView.LastSortOrder == SortOrder.Descending)
                    {
                        renderer2 = new VisualStyleRenderer(VisualStyleElement.Header.SortArrow.SortedDown);
                    }
                    if (renderer2 != null)
                    {
                        Size  sz = renderer2.GetPartSize(g, ThemeSizeType.True);
                        Point pt = renderer2.GetPoint(PointProperty.Offset);
                        // GetPoint() should work, but if it doesn't, put the arrow in the top middle
                        if (pt.X == 0 && pt.Y == 0)
                        {
                            pt = new Point(r.X + (r.Width / 2) - (sz.Width / 2), r.Y);
                        }
                        renderer2.DrawBackground(g, new Rectangle(pt, sz));
                    }
                }
                else
                {
                    // No theme support for sort indicators. So, we draw a triangle at the right edge
                    // of the column header.
                    const int triangleHeight = 16;
                    const int triangleWidth  = 16;
                    const int midX           = triangleWidth / 2;
                    const int midY           = (triangleHeight / 2) - 1;
                    const int deltaX         = midX - 2;
                    const int deltaY         = deltaX / 2;

                    Point   triangleLocation = new Point(r.Right - triangleWidth - 2, r.Top + (r.Height - triangleHeight) / 2);
                    Point[] pts = new Point[] { triangleLocation, triangleLocation, triangleLocation };

                    if (this.ListView.LastSortOrder == SortOrder.Ascending)
                    {
                        pts[0].Offset(midX - deltaX, midY + deltaY);
                        pts[1].Offset(midX, midY - deltaY - 1);
                        pts[2].Offset(midX + deltaX, midY + deltaY);
                    }
                    else
                    {
                        pts[0].Offset(midX - deltaX, midY - deltaY);
                        pts[1].Offset(midX, midY + deltaY);
                        pts[2].Offset(midX + deltaX, midY - deltaY);
                    }

                    g.FillPolygon(Brushes.SlateGray, pts);
                    r.Width = r.Width - triangleWidth;
                }
            }

            // Finally draw the text
            TextFormatFlags flags = this.TextFormatFlags;

            if (column.TextAlign == HorizontalAlignment.Center)
            {
                flags |= TextFormatFlags.HorizontalCenter;
            }
            if (column.TextAlign == HorizontalAlignment.Right)
            {
                flags |= TextFormatFlags.Right;
            }

            Font  f     = this.CalculateFont(column);
            Color color = column.HeaderForeColor;

            if (color.IsEmpty)
            {
                color = this.ListView.ForeColor;
            }

            // Tweak the text rectangle a little to improve aethestics
            r.Inflate(-3, 0);
            r.Y -= 2;

            TextRenderer.DrawText(g, column.Text, f, r, color, Color.Transparent, flags);
        }
示例#16
0
        private void DrawVisualStyle(Graphics graphics, VisualStyleElement element, Rectangle bounds)
        {
            VisualStyleRenderer vsRenderer = GetVisualStyleRenderer(element);

            vsRenderer.DrawBackground(graphics, bounds);
        }
示例#17
0
        /// <summary>
        /// Fires the DrawThumb events
        /// </summary>
        /// <param name="hdc">The device context for graphics operations</param>
        protected virtual void OnDrawThumb(IntPtr hdc)
        {
            Graphics graphics = Graphics.FromHdc(hdc);

            graphics.Clip = new Region(this.ThumbBounds);
            if (((this.OwnerDrawParts & TrackBarOwnerDrawParts.Thumb) == TrackBarOwnerDrawParts.Thumb) && !this.DesignMode)
            {
                TrackBarDrawItemEventArgs e = new TrackBarDrawItemEventArgs(graphics, this.ThumbBounds, (TrackBarItemState)this.ThumbState);
                if (this.DrawThumb != null)
                {
                    this.DrawThumb(this, e);
                }
            }
            else
            {
                // Determine the style of the thumb, based on the tickstyle
                NativeMethods.TrackBarParts part = NativeMethods.TrackBarParts.TKP_THUMB;
                if (this.ThumbBounds.Equals(Rectangle.Empty))
                {
                    return;
                }
                switch (this.TickStyle)
                {
                case TickStyle.None:
                case TickStyle.BottomRight:
                    part = (Orientation != Orientation.Horizontal) ? NativeMethods.TrackBarParts.TKP_THUMBRIGHT : NativeMethods.TrackBarParts.TKP_THUMBBOTTOM;
                    break;

                case TickStyle.TopLeft:
                    part = (this.Orientation != Orientation.Horizontal) ? NativeMethods.TrackBarParts.TKP_THUMBLEFT : NativeMethods.TrackBarParts.TKP_THUMBTOP;
                    break;

                case TickStyle.Both:
                    part = (this.Orientation != Orientation.Horizontal) ? NativeMethods.TrackBarParts.TKP_THUMBVERT : NativeMethods.TrackBarParts.TKP_THUMB;
                    break;
                }
                // Perform drawing
                if (VisualStyleRenderer.IsSupported)
                {
                    VisualStyleRenderer vsr = new VisualStyleRenderer("TRACKBAR", (int)part, ThumbState);
                    vsr.DrawBackground(graphics, this.ThumbBounds);
                    graphics.ResetClip();
                    graphics.Dispose();
                    return;
                }
                else
                {
                    switch (part)
                    {
                    case NativeMethods.TrackBarParts.TKP_THUMBBOTTOM:
                        this.DrawPointerDown(graphics);
                        break;

                    case NativeMethods.TrackBarParts.TKP_THUMBTOP:
                        this.DrawPointerUp(graphics);

                        break;

                    case NativeMethods.TrackBarParts.TKP_THUMBLEFT:
                        this.DrawPointerLeft(graphics);

                        break;

                    case NativeMethods.TrackBarParts.TKP_THUMBRIGHT:
                        this.DrawPointerRight(graphics);

                        break;

                    default:
                        if ((this.ThumbState == 3) || !this.Enabled)
                        {
                            ControlPaint.DrawButton(graphics, this.ThumbBounds, ButtonState.All);
                        }
                        else
                        {
                            // Tick-style is both - draw the thumb as a solid rectangle
                            graphics.FillRectangle(SystemBrushes.Control, this.ThumbBounds);
                        }
                        ControlPaint.DrawBorder3D(graphics, this.ThumbBounds, Border3DStyle.Raised);
                        break;
                    }
                }
            }
            graphics.ResetClip();
            graphics.Dispose();
        }
示例#18
0
        public virtual void PaintCellPlusMinus(Graphics dc, Rectangle glyphRect, Node node, TreeListColumn column, TreeList.TextFormatting format)
        {
            if (!Application.RenderWithVisualStyles)
            {
                // find square rect first
                int diff = glyphRect.Height - glyphRect.Width;
                glyphRect.Y      += diff / 2;
                glyphRect.Height -= diff;

                // draw 8x8 box centred
                while (glyphRect.Height > 8)
                {
                    glyphRect.Height -= 2;
                    glyphRect.Y      += 1;
                    glyphRect.X      += 1;
                }

                // make a box
                glyphRect.Width = glyphRect.Height;

                // clear first
                SolidBrush brush = new SolidBrush(format.BackColor);
                if (format.BackColor == Color.Transparent)
                {
                    brush = new SolidBrush(m_owner.BackColor);
                }
                dc.FillRectangle(brush, glyphRect);
                brush.Dispose();

                // draw outline
                Pen p = new Pen(SystemColors.ControlDark);
                dc.DrawRectangle(p, glyphRect);
                p.Dispose();

                p = new Pen(SystemColors.ControlText);

                // reduce box for internal lines
                glyphRect.X     += 2; glyphRect.Y += 2;
                glyphRect.Width -= 4; glyphRect.Height -= 4;

                // draw horizontal line always
                dc.DrawLine(p, glyphRect.X, glyphRect.Y + glyphRect.Height / 2, glyphRect.X + glyphRect.Width, glyphRect.Y + glyphRect.Height / 2);

                // draw vertical line if this should be a +
                if (!node.Expanded)
                {
                    dc.DrawLine(p, glyphRect.X + glyphRect.Width / 2, glyphRect.Y, glyphRect.X + glyphRect.Width / 2, glyphRect.Y + glyphRect.Height);
                }

                p.Dispose();
                return;
            }

            VisualStyleElement element = VisualStyleElement.TreeView.Glyph.Closed;

            if (node.Expanded)
            {
                element = VisualStyleElement.TreeView.Glyph.Opened;
            }

            if (VisualStyleRenderer.IsElementDefined(element))
            {
                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(dc, glyphRect);
            }
        }
示例#19
0
        /// <summary>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = false;
            var rect = e.Bounds;

            if (rect.Height == 0)
            {
                //在展开节点的时候会出现根节点绘制错误的问题
                return;
            }
            if ((e.State & TreeNodeStates.Selected) != 0)
            {
                e.Graphics.FillRectangle(
                    (e.State & TreeNodeStates.Focused) != 0 ? SystemBrushes.Highlight : SystemBrushes.Control, rect);
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, rect);
            }
            var indentWidth = DatatreeView.Indent * e.Node.Level + 25;

            e.Graphics.DrawRectangle(SystemPens.Control, rect);
            var stringRect = new Rectangle(e.Bounds.X + indentWidth, e.Bounds.Y, colName.Width - indentWidth,
                                           e.Bounds.Height);

            var treeNameString = e.Node.Text;

            if (treeNameString.EndsWith(ConstMgr.ArrayMark))
            {
                //Array_Mark 在计算路径的时候使用,不过,在表示的时候,则不能表示
                treeNameString = treeNameString.Substring(0, treeNameString.Length - ConstMgr.ArrayMark.Length);
            }
            if (treeNameString.EndsWith(ConstMgr.DocumentMark))
            {
                //Document_Mark 在计算路径的时候使用,不过,在表示的时候,则不能表示
                treeNameString = treeNameString.Substring(0, treeNameString.Length - ConstMgr.DocumentMark.Length);
            }
            //感谢cyrus的建议,选中节点的文字表示,底色变更
            if ((e.State & TreeNodeStates.Selected) != 0 && (e.State & TreeNodeStates.Focused) != 0)
            {
                e.Graphics.DrawString(treeNameString, Font, new SolidBrush(SystemColors.HighlightText), stringRect);
            }
            else
            {
                e.Graphics.DrawString(treeNameString, Font, new SolidBrush(Color.Black), stringRect);
            }
            //CSHARP-1066: Change BsonElement from a class to a struct.
            BsonElement mElement;

            if (e.Node.Tag != null)
            {
                if (e.Node.Tag.GetType() != typeof(BsonElement))
                {
                    mElement = new BsonElement("", (BsonValue)e.Node.Tag);
                }
                else
                {
                    mElement = (BsonElement)e.Node.Tag;
                }
            }
            var mValue = e.Node.Tag as BsonValue;

            //画框
            if (e.Node.GetNodeCount(true) > 0 ||
                (mElement.Value != null && (mElement.Value.IsBsonDocument || mElement.Value.IsBsonArray)))
            {
                //感谢Cyrus测试出来的问题:RenderWithVisualStyles应该加上去的。
                if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
                {
                    var leftPoint = e.Bounds.X + indentWidth - 20;
                    //感谢 Shadower http://home.cnblogs.com/u/14697/ 贡献的代码
                    var thisNode = e.Node;
                    var glyph    = thisNode.IsExpanded
                        ? VisualStyleElement.TreeView.Glyph.Opened
                        : VisualStyleElement.TreeView.Glyph.Closed;
                    var vsr = new VisualStyleRenderer(glyph);
                    vsr.DrawBackground(e.Graphics, new Rectangle(leftPoint, e.Bounds.Y + 4, 16, 16));
                }
                else
                {
                    var leftPoint = e.Bounds.X + indentWidth - 20;
                    e.Graphics.DrawRectangle(new Pen(Color.Black), new Rectangle(leftPoint, e.Bounds.Y + 4, 12, 12));
                    var leftMid   = new Point(leftPoint + 2, e.Bounds.Y + 10);
                    var rightMid  = new Point(leftPoint + 10, e.Bounds.Y + 10);
                    var topMid    = new Point(leftPoint + 6, e.Bounds.Y + 6);
                    var bottomMid = new Point(leftPoint + 6, e.Bounds.Y + 14);
                    e.Graphics.DrawLine(new Pen(Color.Black), leftMid, rightMid);
                    if (!e.Node.IsExpanded)
                    {
                        e.Graphics.DrawLine(new Pen(Color.Black), topMid, bottomMid);
                    }
                }
            }

            for (var intColumn = 1; intColumn < 3; intColumn++)
            {
                rect.Offset(listView.Columns[intColumn - 1].Width, 0);
                rect.Width = listView.Columns[intColumn].Width;
                e.Graphics.DrawRectangle(SystemPens.Control, rect);
                if (mElement.Value != null || mValue != null)
                {
                    var strColumnText = string.Empty;
                    if (intColumn == 1)
                    {
                        if (mElement.Value != null)
                        {
                            if (!mElement.Value.IsBsonDocument && !mElement.Value.IsBsonArray)
                            {
                                if (mElement.Value.IsValidDateTime)
                                {
                                    if (IsUTC)
                                    {
                                        strColumnText = mElement.Value.AsBsonDateTime.ToUniversalTime().ToString();
                                    }
                                    else
                                    {
                                        strColumnText = mElement.Value.AsBsonDateTime.ToLocalTime().ToString();
                                    }
                                }
                                else
                                {
                                    strColumnText = mElement.Value.ToString();
                                }
                            }
                        }
                        else
                        {
                            if (mValue != null)
                            {
                                //Type这里已经有表示Type的标识了,这里就不重复显示了。
                                if (!mValue.IsBsonDocument && !mValue.IsBsonArray)
                                {
                                    if (e.Node.Level > 0)
                                    {
                                        //根节点有Value,可能是ID,用来取得选中节点的信息
                                        strColumnText = mValue.ToString();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        strColumnText = mElement.Value != null
                            ? mElement.Value.GetType().Name.Substring(4)
                            : mValue.GetType().Name.Substring(4);
                    }

                    var flags = TextFormatFlags.EndEllipsis;
                    switch (listView.Columns[intColumn].TextAlign)
                    {
                    case HorizontalAlignment.Center:
                        flags |= TextFormatFlags.HorizontalCenter;
                        break;

                    case HorizontalAlignment.Left:
                        flags |= TextFormatFlags.Left;
                        break;

                    case HorizontalAlignment.Right:
                        flags |= TextFormatFlags.Right;
                        break;

                    default:
                        break;
                    }

                    rect.Y++;
                    if ((e.State & TreeNodeStates.Selected) != 0 &&
                        (e.State & TreeNodeStates.Focused) != 0)
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect,
                                              SystemColors.HighlightText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, e.Node.ForeColor,
                                              e.Node.BackColor, flags);
                    }
                    rect.Y--;
                }
            }
        }
示例#20
0
        public override void DrawDayHeader(System.Drawing.Graphics g, System.Drawing.Rectangle rect, DateTime date)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            // Header background
            bool isToday = date.Date.Equals(DateTime.Now.Date);

            Rectangle rHeader = rect;

            rHeader.X++;

            if (VisualStyleRenderer.IsSupported)
            {
                bool hasTodayColor = Theme.HasAppColor(UITheme.AppColor.Today);
                var  headerState   = VisualStyleElement.Header.Item.Normal;

                if (isToday && !hasTodayColor)
                {
                    headerState = VisualStyleElement.Header.Item.Hot;
                }

                var renderer = new VisualStyleRenderer(headerState);
                renderer.DrawBackground(g, rHeader);

                if (isToday && hasTodayColor)
                {
                    rHeader.X--;

                    using (var brush = new SolidBrush(Theme.GetAppDrawingColor(UITheme.AppColor.Today, 64)))
                        g.FillRectangle(brush, rHeader);
                }
            }
            else             // classic theme
            {
                rHeader.Y++;

                var headerBrush = (isToday ? SystemBrushes.ButtonHighlight : SystemBrushes.ButtonFace);
                g.FillRectangle(headerBrush, rHeader);

                ControlPaint.DrawBorder3D(g, rHeader, Border3DStyle.Raised);
            }

            // Header text
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;

            // Day of month
            TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine;

            using (Font font = new Font("Tahoma", 9, FontStyle.Bold))
            {
                if (DOWStyle == DOWNameStyle.None)
                {
                    flags |= TextFormatFlags.HorizontalCenter;
                }

                string dayNum = date.ToString(" d");
                TextRenderer.DrawText(g, dayNum, font, rect, SystemColors.WindowText, flags);

                if (DOWStyle == DOWNameStyle.Long)
                {
                    int strWidth = TextRenderer.MeasureText(g, dayNum, font).Width;

                    rect.Width -= strWidth;
                    rect.X     += strWidth;
                }
            }

            // Day of week
            if (DOWStyle != DOWNameStyle.None)
            {
                if (DOWStyle == DOWNameStyle.Long)
                {
                    flags |= TextFormatFlags.HorizontalCenter;
                }
                else
                {
                    flags |= TextFormatFlags.Right;
                }

                using (Font font = new Font("Tahoma", 8, FontStyle.Regular))
                {
                    string dayName;

                    if (DOWStyle == DOWNameStyle.Long)
                    {
                        dayName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(date.DayOfWeek);
                    }
                    else
                    {
                        dayName = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedDayName(date.DayOfWeek);
                    }

                    TextRenderer.DrawText(g, dayName, font, rect, SystemColors.WindowText, flags);
                }
            }
        }
        public override void Paint(GraphicsSettings gs, Rectangle clipRect)
        {
            using (SolidBrush brush = new SolidBrush(Host.TextColor))
            {
                Rectangle rc     = Rectangle;
                int       offset = 0;

                if (Parent.LayoutController != null)
                {
                    offset = Parent.LayoutController.CurrentHorizontalScrollPosition;
                    rc.X  -= offset;
                }

                if (_displayMode == DisplayMode.Header)
                {
                    if (VisualStyleRenderer.IsSupported)
                    {
                        VisualStyleRenderer renderer = GetRenderer();

                        renderer.DrawBackground(gs.Graphics, rc);
                    }
                    else
                    {
                        gs.Graphics.FillRectangle(SystemBrushes.Control, rc);

                        if (_leftMouseButtonPressed)
                        {
                            ControlPaint.DrawBorder3D(gs.Graphics, rc, Border3DStyle.Sunken);
                        }
                        else
                        {
                            ControlPaint.DrawBorder3D(gs.Graphics, rc, Border3DStyle.Raised);
                        }
                    }
                }
                else
                {
                    DrawBox(gs.Graphics, rc);
                }

                DrawIcon(gs.Graphics, ref rc);

                const int textMargin = 2;

                rc.X     += textMargin;
                rc.Width -= textMargin;

                if (Parent.LayoutController != null)
                {
                    if (_column.ShowHeaderSortArrow)
                    {
                        rc.Width -= _arrowWidth + _arrowSpaceXMargin * 2;
                    }
                }

                rc.Y -= 2;

                DrawCaption(gs, rc);

                DrawSortArrow(gs, rc);
            }
        }
示例#22
0
        internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
        {
            Rectangle  recBounds   = this.GetTabRect(nIndex);
            RectangleF tabTextArea = (RectangleF)this.GetTabRect(nIndex);
            bool       bSelected   = (this.SelectedIndex == nIndex);
            bool       bHot        = false;

            VisualStyleRenderer render = new VisualStyleRenderer(VisualStyleElement.Tab.Pane.Normal);


            if (tabPage.Tag != null)
            {
                bHot = (bool)tabPage.Tag;
            }

            //Align?
            if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
            {
                recBounds.Offset(2, 0);
                recBounds.Width = recBounds.Width + 1;
            }
            else
            {
                //right or left
                recBounds.Offset(0, 1);
                recBounds.Height   = recBounds.Height + 0;
                tabTextArea.Height = tabTextArea.Height - 2;
                tabTextArea.Offset(-2, 0);
                //and selected
                if (bSelected)
                {
                    if (Alignment == TabAlignment.Left)
                    {
                        recBounds.Width   = recBounds.Width + 3;
                        tabTextArea.Width = tabTextArea.Width + 3;
                    }
                    else
                    {
                        recBounds.X       = recBounds.X - 3;
                        recBounds.Width   = recBounds.Width + 3;
                        tabTextArea.X     = tabTextArea.X - 3;
                        tabTextArea.Width = tabTextArea.Width + 3;
                    }
                }
            }


            //Tab Selected
            if (bSelected)
            {
                //highter if selected and no multiline
                if (this.Multiline != true)
                {
                    if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                    {
                        recBounds.Height = recBounds.Height + 2;
                        recBounds.Width  = recBounds.Width - 1;
                    }
                }
                else //lower profile
                {
                    if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                    {
                        recBounds.Y      = recBounds.Y + 1;
                        recBounds.Height = recBounds.Height + 1;
                        recBounds.Width  = recBounds.Width - 1;
                        tabTextArea.Offset(0, 1);
                    }
                }
                render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed);
                render.DrawBackground(g, recBounds);
                render.DrawEdge(g, recBounds, Edges.Diagonal, EdgeStyle.Sunken, EdgeEffects.Flat);
            }
            //Tab HotTrack
            else if (bHot)
            {
                if (bSelected) //hot and selected Multiline
                {
                    //highter if selected and no multiline
                    if (this.Multiline != true)
                    {
                        if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                        {
                            recBounds.Height = recBounds.Height + 2;
                            recBounds.Width  = recBounds.Width - 1;
                        }
                    }
                    else//lower if selected and multiline
                    {
                        if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                        {
                            recBounds.Y      = recBounds.Y + 1;
                            recBounds.Height = recBounds.Height + 1;
                            recBounds.Width  = recBounds.Width - 1;
                            tabTextArea.Offset(0, 1);
                        }
                    }
                }
                //tab Hot and not selected
                else
                {
                    if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                    {
                        //smaller if not selected, text lower
                        recBounds.Y      = recBounds.Y + 3;
                        recBounds.Height = recBounds.Height - 2;
                        tabTextArea.Offset(0, 2);
                    }
                }

                render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot);
                render.DrawBackground(g, recBounds);
                render.DrawEdge(g, recBounds, Edges.Diagonal, EdgeStyle.Sunken, EdgeEffects.Flat);
            }

            //Tab Normal
            else
            {
                //smaller if not selected, text lower
                if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
                {
                    recBounds.Y      = recBounds.Y + 3;
                    recBounds.Height = recBounds.Height - 2;
                    tabTextArea.Offset(0, 2);
                }
                render = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
                render.DrawBackground(g, recBounds);
                render.DrawEdge(g, recBounds, Edges.Diagonal, EdgeStyle.Sunken, EdgeEffects.Flat);
            }

            //DrawBottomLine
            if (Alignment != TabAlignment.Top)
            {
                render.DrawEdge(g, recBounds, Edges.Bottom, EdgeStyle.Sunken, EdgeEffects.Flat);
            }


            //image management
            if ((tabPage.ImageIndex >= 0) && ((ImageList != null)) && ((ImageList.Images[tabPage.ImageIndex] != null)))
            {
                int       nLeftMargin  = 8;
                int       nRightMargin = 1;
                Image     img          = ImageList.Images[tabPage.ImageIndex];
                Rectangle rimage       = new Rectangle(recBounds.X + nLeftMargin, recBounds.Y + 1, img.Width, img.Height);
                float     nAdj         = (float)(nLeftMargin + img.Width + nRightMargin);
                // adjust rectangles for top, bottom and ExtendedLayout
                if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom || _useExtendedLayout == true)
                {
                    nAdj = (float)(nLeftMargin + img.Width + nRightMargin);

                    rimage.Y          += (recBounds.Height - img.Height) / 2;
                    tabTextArea.X     += nAdj;
                    tabTextArea.Width -= nAdj;

                    //selected
                    if (bSelected)
                    {
                        //normal
                        if (!_useExtendedLayout)
                        {
                            rimage.Offset(0, -1);
                        }
                        //exted Layout
                        else
                        {
                            rimage.Offset(2, 0);
                        }
                    }
                }
                else
                {
                    //not ExtendedLayout, not rotate if left tab page
                    if (_useExtendedLayout == false)
                    {
                        img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                        //rimage.X += (recBounds.Width - img.Width) / 2;
                        rimage.X -= 4;
                        rimage.Y += 3;

                        nAdj                = (float)(10 + img.Height);
                        tabTextArea.Y      += img.Height;
                        tabTextArea.Height -= img.Height;
                    }
                }

                g.DrawImage(img, rimage);
            }

            //string management
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            if (FlagControl)
            {
                stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            }
            else
            {
                stringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
            }
            Brush br;

            if (!bHot)
            {
                br = new SolidBrush(tabPage.ForeColor);
            }
            else
            {
                if (_useKrypton)
                {
                    br = new SolidBrush(_hotForeColor);
                }
                else
                {
                    br = new SolidBrush(tabPage.ForeColor);
                }
            }

            //use AntiAlias
            if (Utility.IsVista())
            {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            }
            else
            {
                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            }


            //Vertical Orientation
            if ((this.Alignment == TabAlignment.Left) || (this.Alignment == TabAlignment.Right))
            {
                //not ExtendedLayout
                if (_useExtendedLayout == false)
                {
                    stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
                }
                else
                //Extended Layout
                {
                    tabTextArea.Offset(1, 2);
                    tabTextArea.Width        = tabTextArea.Width - 2;
                    stringFormat.FormatFlags = StringFormatFlags.NoWrap;
                    stringFormat.Trimming    = StringTrimming.EllipsisCharacter;
                }
            }
            g.DrawString(tabPage.Text, Font, br, tabTextArea, stringFormat);
            bHot = false;
        }
示例#23
0
        private void PaintPriv(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (g == null)
            {
                base.OnPaint(e); return;
            }

            int nNormPos = m_nPosition - m_nMinimum;
            int nNormMax = m_nMaximum - m_nMinimum;

            if (nNormMax <= 0)
            {
                Debug.Assert(false); nNormMax = 100;
            }
            if (nNormPos < 0)
            {
                Debug.Assert(false); nNormPos = 0;
            }
            if (nNormPos > nNormMax)
            {
                Debug.Assert(false); nNormPos = nNormMax;
            }

            Rectangle          rectClient = this.ClientRectangle;
            Rectangle          rectDraw;
            VisualStyleElement vse = VisualStyleElement.ProgressBar.Bar.Normal;

            if (VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(vse))
            {
                VisualStyleRenderer vsr = new VisualStyleRenderer(vse);

                if (vsr.IsBackgroundPartiallyTransparent())
                {
                    vsr.DrawParentBackground(g, rectClient, this);
                }

                vsr.DrawBackground(g, rectClient);

                rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient);
            }
            else
            {
                g.FillRectangle(SystemBrushes.Control, rectClient);

                Pen penGray  = SystemPens.ControlDark;
                Pen penWhite = SystemPens.ControlLight;
                g.DrawLine(penGray, 0, 0, rectClient.Width - 1, 0);
                g.DrawLine(penGray, 0, 0, 0, rectClient.Height - 1);
                g.DrawLine(penWhite, rectClient.Width - 1, 0,
                           rectClient.Width - 1, rectClient.Height - 1);
                g.DrawLine(penWhite, 0, rectClient.Height - 1,
                           rectClient.Width - 1, rectClient.Height - 1);

                rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1,
                                         rectClient.Width - 2, rectClient.Height - 2);
            }

            int nDrawWidth = (int)((float)rectDraw.Width * (float)nNormPos /
                                   (float)nNormMax);

            Color clrStart = AppDefs.ColorQualityLow;
            Color clrEnd   = AppDefs.ColorQualityHigh;

            if (!this.Enabled)
            {
                clrStart = UIUtil.ColorToGrayscale(SystemColors.ControlDark);
                clrEnd   = UIUtil.ColorToGrayscale(SystemColors.ControlLight);
            }

            bool bRtl = (this.RightToLeft == RightToLeft.Yes);

            if (bRtl)
            {
                Color clrTemp = clrStart;
                clrStart = clrEnd;
                clrEnd   = clrTemp;
            }

            // Workaround for Windows <= XP
            Rectangle rectGrad = new Rectangle(rectDraw.X, rectDraw.Y,
                                               rectDraw.Width, rectDraw.Height);

            if (!WinUtil.IsAtLeastWindowsVista && !NativeLib.IsUnix())
            {
                rectGrad.Inflate(1, 0);
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(rectGrad,
                                                                       clrStart, clrEnd, LinearGradientMode.Horizontal))
            {
                g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
                                        rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
            }

            PaintText(g, rectDraw, bRtl);
        }
示例#24
0
        public static void DrawArrowButton(Graphics g, Rectangle_ bounds, ScrollBarArrowButtonState state)
        {
            if (!IsSupported)
            {
                throw new InvalidOperationException();
            }

            VisualStyleRenderer vsr;

            switch (state)
            {
            case ScrollBarArrowButtonState.DownDisabled:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownDisabled);
                break;

            case ScrollBarArrowButtonState.DownHot:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownHot);
                break;

            case ScrollBarArrowButtonState.DownNormal:
            default:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownNormal);
                break;

            case ScrollBarArrowButtonState.DownPressed:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.DownPressed);
                break;

            case ScrollBarArrowButtonState.LeftDisabled:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftDisabled);
                break;

            case ScrollBarArrowButtonState.LeftHot:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftHot);
                break;

            case ScrollBarArrowButtonState.LeftNormal:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftNormal);
                break;

            case ScrollBarArrowButtonState.LeftPressed:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.LeftPressed);
                break;

            case ScrollBarArrowButtonState.RightDisabled:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightDisabled);
                break;

            case ScrollBarArrowButtonState.RightHot:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightHot);
                break;

            case ScrollBarArrowButtonState.RightNormal:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightNormal);
                break;

            case ScrollBarArrowButtonState.RightPressed:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.RightPressed);
                break;

            case ScrollBarArrowButtonState.UpDisabled:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpDisabled);
                break;

            case ScrollBarArrowButtonState.UpHot:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpHot);
                break;

            case ScrollBarArrowButtonState.UpNormal:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpNormal);
                break;

            case ScrollBarArrowButtonState.UpPressed:
                vsr = new VisualStyleRenderer(VisualStyleElement.ScrollBar.ArrowButton.UpPressed);
                break;
            }

            vsr.DrawBackground(g, bounds);
        }
示例#25
0
        private void DrawButton(Graphics e, mcButtonState state, mcHeaderButtons button, Rectangle rect)
        {
            Bitmap image = null;
            int    x     = 0;
            int    y     = 0;
            int    corr  = 0;

            if (Application.RenderWithVisualStyles)
            {
                VisualStyleElement element = VisualStyleElement.Button.PushButton.Normal;

                if (m_calendar.Enabled)
                {
                    if (state == mcButtonState.Hot)
                    {
                        element = VisualStyleElement.Button.PushButton.Hot;
                    }
                    else if (state == mcButtonState.Inactive)
                    {
                        element = VisualStyleElement.Button.PushButton.Disabled;
                    }
                    else if (state == mcButtonState.Pushed)
                    {
                        element = VisualStyleElement.Button.PushButton.Pressed;
                    }
                }
                else
                {
                    element = VisualStyleElement.Button.PushButton.Disabled;
                }

                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(e, rect);
                switch (button)
                {
                case mcHeaderButtons.PreviousMonth:
                {
                    image = m_prevMonthVs;
                    x     = rect.Left + 5;
                    y     = rect.Top + 5;
                    break;
                }

                case mcHeaderButtons.PreviousYear:
                {
                    image = m_prevYearVs;
                    x     = rect.Left + 4;
                    y     = rect.Top + 5;
                    break;
                }

                case mcHeaderButtons.NextMonth:
                {
                    image = m_nextMonthVs;
                    x     = rect.Right - 13;
                    y     = rect.Top + 5;
                    break;
                }

                case mcHeaderButtons.NextYear:
                {
                    image = m_nextYearVs;
                    x     = rect.Right - 16;
                    y     = rect.Top + 5;
                    break;
                }
                }

                if ((m_calendar.Enabled) && (state != mcButtonState.Inactive))
                {
                    e.DrawImageUnscaled(image, new Point(x, y));
                }
                else
                {
                    ControlPaint.DrawImageDisabled(e, image, x, y, Color.Transparent);
                }
            }
            else
            {
                ButtonState btnState = ButtonState.Normal;
                if (m_calendar.Enabled)
                {
                    if (state == mcButtonState.Hot)
                    {
                        btnState = ButtonState.Normal;
                    }
                    else if (state == mcButtonState.Inactive)
                    {
                        btnState = ButtonState.Inactive;
                    }
                    else if (state == mcButtonState.Pushed)
                    {
                        btnState = ButtonState.Pushed;
                    }
                }
                else
                {
                    btnState = ButtonState.Inactive;
                }

                switch (button)
                {
                case mcHeaderButtons.PreviousMonth:
                {
                    ControlPaint.DrawScrollButton(e, rect, ScrollButton.Left, btnState);
                    break;
                }

                case mcHeaderButtons.NextMonth:
                {
                    ControlPaint.DrawScrollButton(e, rect, ScrollButton.Right, btnState);
                    break;
                }

                case mcHeaderButtons.NextYear:
                {
                    ControlPaint.DrawButton(e, rect, btnState);
                    if (state == mcButtonState.Pushed)
                    {
                        corr = 1;
                    }
                    if ((m_calendar.Enabled) && (m_nextYearBtnState != mcButtonState.Inactive))
                    {
                        e.DrawImage(m_nextYear, new Point(rect.Left + 3, rect.Top + 2 + corr));
                    }
                    else
                    {
                        e.DrawImage(m_nextYearDisabled, new Point(rect.Left + 3, rect.Top + 2 + corr));
                    }

                    break;
                }

                case mcHeaderButtons.PreviousYear:
                {
                    ControlPaint.DrawButton(e, rect, btnState);
                    if (state == mcButtonState.Pushed)
                    {
                        corr = 1;
                    }
                    if ((m_calendar.Enabled) && (m_prevYearBtnState != mcButtonState.Inactive))
                    {
                        e.DrawImage(m_prevYear, new Point(rect.Left, rect.Top + 2 + corr));
                    }
                    else
                    {
                        e.DrawImage(m_prevYearDisabled, new Point(rect.Left, rect.Top + 2 + corr));
                    }

                    break;
                }
                }
            }
        }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            TreeGridNode node = this.OwningNode;

            if (node == null)
            {
                return;
            }

            Image image = node.Image;

            if (this._imageHeight == 0 && image != null)
            {
                this.UpdateStyle();
            }

            // paint the cell normally
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            // TODO: Indent width needs to take image size into account
            Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, INDENT_WIDTH, cellBounds.Height - 1);
            int       glyphHalf = glyphRect.Width / 2;

            //TODO: This painting code needs to be rehashed to be cleaner
            int level = this.Level;

            //TODO: Rehash this to take different Imagelayouts into account. This will speed up drawing
            //		for images of the same size (ImageLayout.None)
            if (image != null)
            {
                Point pp;
                if (_imageHeight > cellBounds.Height)
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, cellBounds.Y + _imageHeightOffset);
                }
                else
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, (cellBounds.Height / 2 - _imageHeight / 2) + cellBounds.Y);
                }

                // Graphics container to push/pop changes. This enables us to set clipping when painting
                // the cell's image -- keeps it from bleeding outsize of cells.
                System.Drawing.Drawing2D.GraphicsContainer gc = graphics.BeginContainer();
                {
                    graphics.SetClip(cellBounds);
                    graphics.DrawImageUnscaled(image, pp);
                }
                graphics.EndContainer(gc);
            }

            // Paint tree lines
            if (node._grid.ShowLines)
            {
                using (Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f))
                {
                    linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                    bool isLastSibling  = node.IsLastSibling;
                    bool isFirstSibling = node.IsFirstSibling;
                    if (node.Level == 1)
                    {
                        // the Root nodes display their lines differently
                        if (isFirstSibling && isLastSibling)
                        {
                            // only node, both first and last. Just draw horizontal line
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isFirstSibling)
                        {
                            // first sibling doesn't draw the line extended above. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.X + 4, cellBounds.Bottom);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }
                    }
                    else
                    {
                        if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }

                        // paint lines of previous levels to the root
                        TreeGridNode previousNode   = node.Parent;
                        int          horizontalStop = (glyphRect.X + 4) - INDENT_WIDTH;

                        while (!previousNode.IsRoot)
                        {
                            if (previousNode.HasChildren && !previousNode.IsLastSibling)
                            {
                                // paint vertical line
                                graphics.DrawLine(linePen, horizontalStop, cellBounds.Top, horizontalStop, cellBounds.Bottom);
                            }
                            previousNode   = previousNode.Parent;
                            horizontalStop = horizontalStop - INDENT_WIDTH;
                        }
                    }
                }
            }

            if (node.HasChildren || node._grid.VirtualNodes)
            {
                // Ensure that visual styles are supported.
                if (Application.RenderWithVisualStyles)
                {
                    VisualStyleRenderer rOpen   = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
                    VisualStyleRenderer rClosed = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);

                    // Paint node glyphs
                    if (node.IsExpanded)
                    {
                        //node._grid.rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                        rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                    }
                    else
                    {
                        //node._grid.rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                        rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                    }
                }
                else
                {
                    int h = 8;
                    int w = 8;
                    int x = glyphRect.X;
                    int y = glyphRect.Y + (glyphRect.Height / 2) - 4;
                    //MessageBox.Show("x = " + x.ToString() + ", y= " + y.ToString());

                    graphics.DrawRectangle(new Pen(SystemBrushes.ControlDark), x, y, w, h);
                    graphics.FillRectangle(new SolidBrush(Color.White), x + 1, y + 1, w - 1, h - 1);
                    graphics.DrawLine(new Pen(new SolidBrush(Color.Black)), x + 2, y + 4, x + w - 2, y + 4);

                    if (!node.IsExpanded)
                    {
                        graphics.DrawLine(new Pen(new SolidBrush(Color.Black)), x + 4, y + 2, x + 4, y + h - 2);
                    }
                }
            }
        }
 public static void DrawHeader(Graphics g, Rectangle bounds, int headerState)
 {
     VisualStyleRenderer.SetParameters(DataGridViewTopLeftHeaderCell.HeaderElement.ClassName, DataGridViewTopLeftHeaderCell.HeaderElement.Part, headerState);
     VisualStyleRenderer.DrawBackground(g, bounds, Rectangle.Truncate(g.ClipBounds));
 }
        // Methods
        protected override void OnPaint(PaintEventArgs e)
        {
            VisualStyleRenderer renderer;

            // Paint parent background
            InvokePaintBackground(this, new PaintEventArgs(e.Graphics, ClientRectangle));

            // Paint background
            renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupHead.Normal);
            renderer.DrawBackground(e.Graphics, new Rectangle(0, 0, e.ClipRectangle.Width, 25));

            // Draw Text
            Rectangle fontRect = new Rectangle(17, 6, this.Width - 17 - 24, this.Height);

            if ((State & StateButtonState.Pressed) != 0)
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, fontRect, SystemColors.InactiveCaption, TextFormatFlags.Top | TextFormatFlags.Left);
            }
            else if ((State & StateButtonState.MouseHover) != 0)
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, fontRect, SystemColors.InactiveCaption, TextFormatFlags.Top | TextFormatFlags.Left);
            }
            else if (!Enabled)
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, fontRect, SystemColors.GrayText, TextFormatFlags.Top | TextFormatFlags.Left);
            }
            else
            {
                TextRenderer.DrawText(e.Graphics, this.Text, this.Font, fontRect, SystemColors.MenuHighlight, TextFormatFlags.Top | TextFormatFlags.Left);
            }

            // Draw button
            if (!collapsed)
            {
                // If pressed
                if ((State & StateButtonState.Pressed) != 0)
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Pressed);
                }

                // If hot
                else if ((State & StateButtonState.MouseHover) != 0)
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Hot);
                }

                // If disabled
                else if (!Enabled)
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal);
                }

                // If normal
                else
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupCollapse.Normal);
                }
            }
            else
            {
                // If pressed
                if ((State & StateButtonState.Pressed) != 0)
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Pressed);
                }

                // If hot
                else if ((State & StateButtonState.MouseHover) != 0)
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Hot);
                }

                // If disabled
                else if (!Enabled)
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Normal);
                }

                // If normal
                else
                {
                    renderer = new VisualStyleRenderer(VisualStyleElement.ExplorerBar.NormalGroupExpand.Normal);
                }
            }

            renderer.DrawBackground(e.Graphics, new Rectangle(this.Width - 22, 3, 20, 20));

            base.OnPaint(e);
        }
 private static void DrawThemedGroupBoxNoText(Graphics g, Rectangle bounds, GroupBoxState state)
 {
     InitializeRenderer((int)state);
     visualStyleRenderer.DrawBackground(g, bounds);
 }
示例#30
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (g == null)
            {
                base.OnPaint(e); return;
            }

            int nNormalizedPos = m_nPosition - m_nMinimum;
            int nNormalizedMax = m_nMaximum - m_nMinimum;

            Rectangle rectClient = this.ClientRectangle;
            Rectangle rectDraw;

            if (VisualStyleRenderer.IsSupported)
            {
                VisualStyleRenderer vsr = new VisualStyleRenderer(
                    VisualStyleElement.ProgressBar.Bar.Normal);
                vsr.DrawBackground(g, rectClient);

                rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient);
            }
            else
            {
                g.FillRectangle(SystemBrushes.Control, rectClient);

                g.DrawLine(Pens.Gray, 0, 0, rectClient.Width - 1, 0);
                g.DrawLine(Pens.Gray, 0, 0, 0, rectClient.Height - 1);
                g.DrawLine(Pens.White, rectClient.Width - 1, 0,
                           rectClient.Width - 1, rectClient.Height - 1);
                g.DrawLine(Pens.White, 0, rectClient.Height - 1,
                           rectClient.Width - 1, rectClient.Height - 1);

                rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1,
                                         rectClient.Width - 2, rectClient.Height - 2);
            }

            Rectangle rectGradient = new Rectangle(rectDraw.X, rectDraw.Y,
                                                   rectDraw.Width, rectDraw.Height);

            if ((rectGradient.Width & 1) == 0)
            {
                ++rectGradient.Width;
            }

            int nDrawWidth = (int)((float)rectDraw.Width * ((float)nNormalizedPos /
                                                            (float)nNormalizedMax));

            Color clrStart = Color.FromArgb(255, 128, 0);
            Color clrEnd   = Color.FromArgb(0, 255, 0);

            if (!this.Enabled)
            {
                clrStart = UIUtil.ColorToGrayscale(SystemColors.ControlDark);
                clrEnd   = UIUtil.ColorToGrayscale(SystemColors.Control);
            }

            bool bRtl = (this.RightToLeft == RightToLeft.Yes);

            if (bRtl)
            {
                Color clrTemp = clrStart;
                clrStart = clrEnd;
                clrEnd   = clrTemp;
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(rectGradient,
                                                                       clrStart, clrEnd, LinearGradientMode.Horizontal))
            {
                g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
                                        rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
            }
        }