Exemplo n.º 1
0
        public void VisualStyleRenderer_DrawEdge_NullDc_ThrowsArgumentNullException()
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);

            Assert.Throws <ArgumentNullException>("dc", () => renderer.DrawEdge(null, new Rectangle(1, 2, 3, 4), Edges.Top, EdgeStyle.Bump, EdgeEffects.FillInterior));
        }
Exemplo n.º 2
0
        public void VisualStyleRenderer_SetParameters_InvalidElement_ThrowsArgumentException(VisualStyleElement element)
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);

            Assert.Throws <ArgumentException>(null, () => renderer.SetParameters(element));
        }
Exemplo n.º 3
0
        private void _secondaryPanel_Paint(object sender, PaintEventArgs e)
        {
            VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.CreateElement("TASKDIALOG", 8, 0));

            renderer.DrawBackground(e.Graphics, _secondaryPanel.ClientRectangle, e.ClipRectangle);
        }
Exemplo n.º 4
0
 public void VisualStyleRenderer_IsElementDefined_NullElement_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("element", () => VisualStyleRenderer.IsElementDefined(null));
 }
Exemplo n.º 5
0
        public static void DrawRadioButton(Graphics g, Point glyphLocation, Rectangle textBounds, string radioButtonText, Font font, TextFormatFlags flags, Image image, Rectangle imageBounds, bool focused, RadioButtonState state)
        {
            Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));

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

                vsr.DrawBackground(g, bounds);

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

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

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

                case RadioButtonState.CheckedHot:
                case RadioButtonState.CheckedNormal:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Checked);
                    break;

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

                case RadioButtonState.UncheckedDisabled:
                case RadioButtonState.UncheckedPressed:
                    ControlPaint.DrawRadioButton(g, bounds, ButtonState.Inactive);
                    break;

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

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

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

                if (radioButtonText != String.Empty)
                {
                    TextRenderer.DrawText(g, radioButtonText, font, textBounds, SystemColors.ControlText, flags);
                }
            }
        }
Exemplo n.º 6
0
 public static bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state)
 {
     return(IsThemePartDefined(new SafeThemeHandle(rnd.Handle, false), part, state));
 }
Exemplo n.º 7
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;

        int bmpWidth = indentation;

        if (_nodeLinesNeeded)
        {
            bmpWidth += INDENT_WIDTH;
        }
        else
        {
            bmpWidth += 1;
        }

        if (_sourceControl.ShowCheckBoxes)
        {
            bmpWidth += 16;
        }
        else if (nodeImage != null)
        {
            bmpWidth += nodeImage.Width;
        }

        if (bmpWidth == 0)
        {
            return(null);
        }

        // create a bitmap that will be composed of the node's image and the glyphs/lines/indentation
        Bitmap composite = new Bitmap(bmpWidth, _itemHeight);

        using (Graphics g = Graphics.FromImage(composite)) {
            if (_nodeLinesNeeded)
            {
                using (Pen dotted = new Pen(Color.Gray)) {
                    dotted.DashStyle = 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);
                        }
                    }
                }
            }

            if (_sourceControl.ShowCheckBoxes)
            {
                // leave space for checkbox glyph
            }
            else if (nodeImage != null)
            {
                // composite the image associated with node (appears at far right)
                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);
    }
Exemplo n.º 8
0
        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 bool IsPartDefined(this VisualStyleRenderer rnd, int part, int state) => IsThemePartDefined(rnd.GetSafeHandle(), part, state);
 private static SafeThemeHandle GetSafeHandle(this VisualStyleRenderer rnd) => new SafeThemeHandle(rnd.Handle, false);
 public static uint GetTransitionDuration(this VisualStyleRenderer rnd, int toState, int fromState = 0)
 {
     GetThemeTransitionDuration(rnd.GetSafeHandle(), rnd.Part, fromState == 0 ? rnd.State : fromState, toState, (int)IntegerListProperty.TransitionDuration, out var dwDuration);
     return(dwDuration);
 }
        private void RenderOnComposition(RenderContext context)
        {
            // Convert the clipping rectangle from floating to int version
            RectangleF rectClipF = context.Graphics.ClipBounds;
            Rectangle  rectClip  = new Rectangle((int)rectClipF.X, (int)rectClipF.Y,
                                                 (int)rectClipF.Width, (int)rectClipF.Height);

            // No point drawing unless some of the client fits into the clipping area
            if (rectClip.IntersectsWith(ClientRectangle))
            {
                // Get the hDC for the graphics instance and create a memory DC
                IntPtr gDC = context.Graphics.GetHdc();
                IntPtr mDC = PI.CreateCompatibleDC(gDC);

                PI.BITMAPINFO bmi = new PI.BITMAPINFO();
                bmi.biSize        = Marshal.SizeOf(bmi);
                bmi.biWidth       = ClientWidth;
                bmi.biHeight      = -ClientHeight;
                bmi.biCompression = 0;
                bmi.biBitCount    = 32;
                bmi.biPlanes      = 1;

                // Create a device independant bitmp and select into the memory DC
                IntPtr hDIB = PI.CreateDIBSection(gDC, bmi, 0, 0, IntPtr.Zero, 0);
                PI.SelectObject(mDC, hDIB);

                // To call the renderer we need to convert from Win32 HDC to Graphics object
                using (Graphics bitmapG = Graphics.FromHdc(mDC))
                {
                    Rectangle renderClientRect = new Rectangle(0, 0, ClientWidth, ClientHeight);

                    // Create new render context that uses the bitmap graphics instance
                    using (RenderContext bitmapContext = new RenderContext(context.Control,
                                                                           bitmapG,
                                                                           renderClientRect,
                                                                           context.Renderer))
                    {
                        // Finally we get the renderer to draw the background for the bitmap
                        _mementoBack = context.Renderer.RenderRibbon.DrawRibbonTabContextTitle(_ribbon.RibbonShape, bitmapContext, renderClientRect, _ribbon.StateCommon.RibbonGeneral, this, _mementoBack);
                    }
                }

                // Select the font for use when drawing
                IntPtr hFont = _contentProvider.GetContentShortTextFont(State).ToHfont();
                PI.SelectObject(mDC, hFont);

                // Get renderer for the correct state
                VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);

                // Create structures needed for theme drawing call
                PI.RECT textBounds = new PI.RECT
                {
                    left   = TEXT_SIDE_GAP_COMPOSITION,
                    top    = 0,
                    right  = ClientWidth - (TEXT_SIDE_GAP_COMPOSITION * 2),
                    bottom = ClientHeight
                };
                PI.DTTOPTS dttOpts = new PI.DTTOPTS
                {
                    dwSize    = Marshal.SizeOf(typeof(PI.DTTOPTS)),
                    dwFlags   = PI.DTT_COMPOSITED | PI.DTT_GLOWSIZE | PI.DTT_TEXTCOLOR,
                    crText    = ColorTranslator.ToWin32(SystemColors.ActiveCaptionText),
                    iGlowSize = (_ribbon.Enabled ? 12 : 2)
                };

                // Always draw text centered
                const TextFormatFlags TEXT_FORMAT = TextFormatFlags.SingleLine |
                                                    TextFormatFlags.HorizontalCenter |
                                                    TextFormatFlags.VerticalCenter |
                                                    TextFormatFlags.EndEllipsis;

                // Perform actual drawing
                PI.DrawThemeTextEx(renderer.Handle,
                                   mDC, 0, 0,
                                   GetShortText(), -1, (int)TEXT_FORMAT,
                                   ref textBounds, ref dttOpts);

                // Copy to foreground
                PI.BitBlt(gDC,
                          ClientLocation.X, ClientLocation.Y,
                          ClientWidth, ClientHeight,
                          mDC, 0, 0, 0x00CC0020);

                // Dispose of allocated objects
                PI.DeleteObject(hFont);
                PI.DeleteObject(hDIB);
                PI.DeleteDC(mDC);

                // Must remember to release the hDC
                context.Graphics.ReleaseHdc(gDC);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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)
            {
                e.Graphics.FillRectangle(
                    (e.State & TreeNodeStates.Focused) != 0 ? SystemBrushes.Highlight : SystemBrushes.Control, rect);
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, rect);
            }
            int 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);

            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, Font, new SolidBrush(SystemColors.HighlightText), StringRect);
            }
            else
            {
                e.Graphics.DrawString(TreeNameString, Font, new SolidBrush(Color.Black), StringRect);
            }

            var mElement = e.Node.Tag as BsonElement;
            var 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/ 贡献的代码
                    TreeNode           thisNode = e.Node;
                    VisualStyleElement 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));
                    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 (int 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 != 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)
                            {
                                //Type这里已经有表示Type的标识了,这里就不重复显示了。
                                if (!mValue.IsBsonDocument && !mValue.IsBsonArray)
                                {
                                    if (e.Node.Level > 0)
                                    {
                                        //根节点有Value,可能是ID,用来取得选中节点的信息
                                        strColumnText = mValue.ToString();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        strColumnText = mElement != 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--;
                }
            }
        }
Exemplo n.º 14
0
    /// <summary>
    /// Paints the control (using the Buffered Paint API).
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void _bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs<ComboBoxState> e) {
		VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
		r.DrawParentBackground(e.Graphics, ClientRectangle, this);
		
		DrawComboBox(e.Graphics, ClientRectangle, e.State);

		Rectangle itemBounds = new Rectangle(0, 0, Width - 21, Height);
		itemBounds.Inflate(-1, -3);
		itemBounds.Offset(2, 0);

        // draw the item in the editable portion
        DrawItemState state = DrawItemState.ComboBoxEdit;
        if (Focused && ShowFocusCues && !DroppedDown) state |= DrawItemState.Focus;
        if (!Enabled) state |= DrawItemState.Disabled;
        OnDrawItem(new DrawItemEventArgs(e.Graphics, Font, itemBounds, SelectedIndex, state));
    }
Exemplo n.º 15
0
        /// <summary>
        /// Draws theme text on glass.
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="text"></param>
        /// <param name="font"></param>
        /// <param name="ctlrct"></param>
        /// <param name="iglowSize"></param>
        /// <remarks>This method is courtesy of 版权所有 (I hope the name's right)</remarks>
        public static void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize)
        {
            if (IsGlassEnabled)
            {
                RECT rc  = new RECT();
                RECT rc2 = new RECT();

                rc.Left   = ctlrct.Left;
                rc.Right  = ctlrct.Right;  // +2 * iglowSize;  //make it larger to contain the glow effect
                rc.Top    = ctlrct.Top;
                rc.Bottom = ctlrct.Bottom; // +2 * iglowSize;

                //Just the same rect with rc,but (0,0) at the lefttop
                rc2.Left   = 0;
                rc2.Top    = 0;
                rc2.Right  = rc.Right - rc.Left;
                rc2.Bottom = rc.Bottom - rc.Top;

                IntPtr destdc = GetDC(hwnd);                //hwnd must be the handle of form,not control
                IntPtr Memdc  = CreateCompatibleDC(destdc); // Set up a memory DC where we'll draw the text.
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX; //text format

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight      = -(rc.Bottom - rc.Top); // negative because DrawThemeTextEx() uses a top-down DIB
                dib.bmiHeader.biWidth       = rc.Right - rc.Left;
                dib.bmiHeader.biPlanes      = 1;
                dib.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount    = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0); // Create a 32-bit bmp for use in offscreen drawing when glass is on
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {
                            VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);

                            DTTOPTS dttOpts = new DTTOPTS();

                            dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));

                            dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;


                            dttOpts.iGlowSize = iglowSize;

                            int dtter = DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);

                            bool bbr = BitBlt(destdc, rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top, Memdc, 0, 0, SRCCOPY);

                            if (!bbr)
                            {
                                //throw new Exception("???");
                            }
                        }
                        catch (Exception)
                        {
                            //Console.WriteLine(e.ToString());
                            //throw new Exception("???");
                        }

                        //Remember to clean up
                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);
                    }
                    else
                    {
                        //throw new Exception("???");
                    }
                }
                else
                {
                    //throw new Exception("???");
                }
            }
        }
        private void RenderSeparatorInternal(Graphics g, ToolStripItem item, Rectangle bounds, bool vertical)
        {
            VisualStyleElement separator = (vertical) ? VisualStyleElement.ToolBar.SeparatorHorizontal.Normal : VisualStyleElement.ToolBar.SeparatorVertical.Normal;

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

                vsRenderer.SetParameters(separator.ClassName, separator.Part, GetItemState(item));
                vsRenderer.DrawBackground(g, bounds);
            }
            else
            {
                Color foreColor = item.ForeColor;
                Color backColor = item.BackColor;

                Pen  foreColorPen        = SystemPens.ControlDark;
                bool disposeForeColorPen = GetPen(foreColor, ref foreColorPen);

                try
                {
                    if (vertical)
                    {
                        if (bounds.Height >= 4)
                        {
                            bounds.Inflate(0, -2);     // scoot down 2PX and start drawing
                        }

                        bool rightToLeft = (item.RightToLeft == RightToLeft.Yes);
                        Pen  leftPen     = (rightToLeft) ? SystemPens.ButtonHighlight : foreColorPen;
                        Pen  rightPen    = (rightToLeft) ? foreColorPen : SystemPens.ButtonHighlight;

                        // Draw dark line
                        int startX = bounds.Width / 2;
                        g.DrawLine(leftPen, startX, bounds.Top, startX, bounds.Bottom);

                        // Draw highlight one pixel to the right
                        startX++;
                        g.DrawLine(rightPen, startX, bounds.Top, startX, bounds.Bottom);
                    }
                    else
                    {
                        //
                        // horizontal separator
                        if (bounds.Width >= 4)
                        {
                            bounds.Inflate(-2, 0);        // scoot over 2PX and start drawing
                        }

                        // Draw dark line
                        int startY = bounds.Height / 2;
                        g.DrawLine(foreColorPen, bounds.Left, startY, bounds.Right, startY);

                        // Draw highlight one pixel to the right
                        startY++;
                        g.DrawLine(SystemPens.ButtonHighlight, bounds.Left, startY, bounds.Right, startY);
                    }
                }
                finally
                {
                    if (disposeForeColorPen && foreColorPen != null)
                    {
                        foreColorPen.Dispose();
                    }
                }
            }
        }
Exemplo n.º 17
0
        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            #if DEFAULT_HEADER
            e.DrawDefault = true;
            #else
            using (var sf = new StringFormat())
            {
                Graphics  gfx = e.Graphics;
                Rectangle rt  = e.Bounds;

                #if !MONO
                if (VisualStyleRenderer.IsSupported)
                {
                    VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
                    if ((e.State & ListViewItemStates.Hot) == ListViewItemStates.Hot)
                    {
                        element = VisualStyleElement.Header.Item.Hot;
                    }
                    if ((e.State & ListViewItemStates.Selected) == ListViewItemStates.Selected)
                    {
                        element = VisualStyleElement.Header.Item.Pressed;
                    }

                    var visualStyleRenderer = new VisualStyleRenderer(element);
                    visualStyleRenderer.DrawBackground(gfx, rt);
                }
                else
                {
                    e.DrawBackground();
                }
                #else
                e.DrawBackground();
                #endif

                switch (e.Header.TextAlign)
                {
                case HorizontalAlignment.Left:
                    sf.Alignment = StringAlignment.Near;
                    break;

                case HorizontalAlignment.Right:
                    sf.Alignment = StringAlignment.Far;
                    break;

                case HorizontalAlignment.Center:
                    sf.Alignment = StringAlignment.Center;
                    break;
                }

                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                int w = TextRenderer.MeasureText(" ", Font).Width;
                rt.Inflate(-(w / 5), 0);

                gfx.DrawString(e.Header.Text, Font, Brushes.Black, rt, sf);

                string arrow = "";
                switch (GetColumnSortOrder(e.ColumnIndex))
                {
                case BSDSortOrder.Ascending:
                    arrow = "▲";
                    break;

                case BSDSortOrder.Descending:
                    arrow = "▼";
                    break;
                }

                if (arrow != "")
                {
                    using (var fnt = new Font(Font.FontFamily, Font.SizeInPoints * 0.6f, FontStyle.Regular)) {
                        float aw = gfx.MeasureString(arrow, fnt).Width;
                        float x  = rt.Left + (rt.Width - aw) / 2.0f;
                        gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
                        gfx.DrawString(arrow, fnt, Brushes.Black, x, rt.Top);
                    }
                }
            }
            #endif

            base.OnDrawColumnHeader(e);
        }
Exemplo n.º 18
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 != 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 != null)
                {
                    DrawArrow(new ToolStripArrowRenderEventArgs(g, splitButton, splitButton.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                }
            }
            else
            {
                // Draw the split button button
                Rectangle splitButtonButtonRect = splitButton.ButtonBounds;

                if (splitButton.BackgroundImage != null)
                {
                    // fill in the background image
                    Rectangle fillRect = (splitButton.Selected) ? splitButton.ContentRectangle : bounds;
                    if (splitButton.BackgroundImage != 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));
            }
        }
Exemplo n.º 19
0
        public static void DrawCommandButton(
            Graphics g,
            PushButtonState state,
            Rectangle rect,
            Color backColor,
            Control childControl)
        {
            VisualStyleElement element = null;
            int alpha = 255;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                const string className = "BUTTON";
                const int    partID    = NativeConstants.BP_COMMANDLINK;
                int          stateID;

                switch (state)
                {
                case PushButtonState.Default:
                    stateID = NativeConstants.CMDLS_DEFAULTED;
                    break;

                case PushButtonState.Disabled:
                    stateID = NativeConstants.CMDLS_DISABLED;
                    break;

                case PushButtonState.Hot:
                    stateID = NativeConstants.CMDLS_HOT;
                    break;

                case PushButtonState.Normal:
                    stateID = NativeConstants.CMDLS_NORMAL;
                    break;

                case PushButtonState.Pressed:
                    stateID = NativeConstants.CMDLS_PRESSED;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }

                try
                {
                    element = VisualStyleElement.CreateElement(className, partID, stateID);

                    if (!VisualStyleRenderer.IsElementDefined(element))
                    {
                        element = null;
                    }
                }
                catch (InvalidOperationException)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                switch (state)
                {
                case PushButtonState.Default:
                    element = VisualStyleElement.Button.PushButton.Default;
                    alpha   = 95;
                    break;

                case PushButtonState.Disabled:
                    element = VisualStyleElement.Button.PushButton.Disabled;
                    break;

                case PushButtonState.Hot:
                    element = VisualStyleElement.Button.PushButton.Hot;
                    break;

                case PushButtonState.Normal:
                    alpha   = 0;
                    element = VisualStyleElement.Button.PushButton.Normal;
                    break;

                case PushButtonState.Pressed:
                    element = VisualStyleElement.Button.PushButton.Pressed;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }
            }

            if (element != null)
            {
                try
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                    renderer.DrawParentBackground(g, rect, childControl);
                    renderer.DrawBackground(g, rect);
                }
                catch (Exception)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                ButtonRenderer.DrawButton(g, rect, state);
            }

            if (alpha != 255)
            {
                using (Brush backBrush = new SolidBrush(Color.FromArgb(255 - alpha, backColor)))
                {
                    CompositingMode oldCM = g.CompositingMode;

                    try
                    {
                        g.CompositingMode = CompositingMode.SourceOver;
                        g.FillRectangle(backBrush, rect);
                    }

                    finally
                    {
                        g.CompositingMode = oldCM;
                    }
                }
            }
        }
Exemplo n.º 20
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;
                }
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Prevents a default instance of the <see cref="RendererCache"/> class from being created.
        /// </summary>
        private RendererCache()
        {
            //if visual styles is turned on
            if (Application.RenderWithVisualStyles &&
                VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(headerElement) &&
                VisualStyleRenderer.IsElementDefined(headerElementSel) &&
                VisualStyleRenderer.IsElementDefined(appointmentElement) &&
                VisualStyleRenderer.IsElementDefined(appointmentElementSel) &&
                VisualStyleRenderer.IsElementDefined(bigHeaderElement)
                )
            {
                useVisualStyles     = true;
                headerRender        = new VisualStyleRenderer(headerElement);
                headerRenderWrap    = new VisualStyleWrapper(headerRender, SystemPens.ControlDarkDark);
                bigHeaderRender     = new VisualStyleRenderer(bigHeaderElement);
                bigHeaderRenderWrap = new VisualStyleWrapper(bigHeaderRender, SystemPens.ControlDarkDark);
                headerRenderSel     = new VisualStyleRenderer(headerElementSel);
                headerRenderSelWrap = new VisualStyleWrapper(headerRenderSel, SystemPens.ControlDarkDark);
                //appointmentRender = new VisualStyleRenderer(appointmentElement);
                //appointmentRenderWrap = new VisualStyleWrapper(appointmentRender, SystemPens.ControlDarkDark);
                //appointmentRenderSel = new VisualStyleRenderer(appointmentElementSel);
                //appointmentRenderSelWrap = new VisualStyleWrapper(appointmentRenderSel, SystemPens.ControlDarkDark);

                appointmentRenderWrap = new NonVisualStyleWrapper(SystemColors.ControlText,
                                                                  SystemBrushes.ControlText,
                                                                  SystemColors.ControlDark,
                                                                  SystemBrushes.ControlDark,
                                                                  SystemColors.ControlLightLight,
                                                                  SystemBrushes.ControlLightLight,
                                                                  SystemPens.ControlText);
                ((NonVisualStyleWrapper)appointmentRenderWrap).UsePartialBlend = true;
                appointmentRenderSelWrap = new NonVisualStyleWrapper(SystemColors.HighlightText,
                                                                     SystemBrushes.HighlightText,
                                                                     SystemColors.HighlightText,
                                                                     SystemBrushes.HighlightText,
                                                                     SystemColors.Highlight,
                                                                     SystemBrushes.Highlight,
                                                                     SystemPens.ControlText);
                ((NonVisualStyleWrapper)appointmentRenderSelWrap).UsePartialBlend = true;



                controlRenderWrap   = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.Control, SystemBrushes.Control, SystemPens.ControlText);
                bodyRenderWrap      = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.ControlLightLight, SystemBrushes.ControlLightLight, SystemPens.ControlText);
                bodyLightRenderWrap = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.ControlLightLight, SystemBrushes.ControlLightLight, SystemPens.Control);
            }
            else
            {
                //else non-visual style 'boring' mode
                bigHeaderRenderWrap = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.Control, SystemBrushes.Control, SystemPens.ControlText);
                headerRenderWrap    = new NonVisualStyleWrapper(SystemColors.ControlText,
                                                                SystemBrushes.ControlText,
                                                                SystemColors.Control,
                                                                SystemBrushes.Control,
                                                                SystemColors.ControlLightLight,
                                                                SystemBrushes.ControlLightLight,
                                                                SystemPens.ControlText);
                ((NonVisualStyleWrapper)headerRenderWrap).NoGradientBlend = true;
                headerRenderSelWrap = new NonVisualStyleWrapper(SystemColors.HighlightText,
                                                                SystemBrushes.HighlightText,
                                                                SystemColors.Highlight,
                                                                SystemBrushes.Highlight,
                                                                SystemPens.ControlText);
                appointmentRenderWrap = new NonVisualStyleWrapper(SystemColors.ControlText,
                                                                  SystemBrushes.ControlText,
                                                                  SystemColors.Control,
                                                                  SystemBrushes.Control,
                                                                  SystemColors.ControlLightLight,
                                                                  SystemBrushes.ControlLightLight,
                                                                  SystemPens.ControlText);
                ((NonVisualStyleWrapper)appointmentRenderWrap).UsePartialBlend = true;
                appointmentRenderSelWrap = new NonVisualStyleWrapper(SystemColors.HighlightText,
                                                                     SystemBrushes.HighlightText,
                                                                     SystemColors.HighlightText,
                                                                     SystemBrushes.HighlightText,
                                                                     SystemColors.Highlight,
                                                                     SystemBrushes.Highlight,
                                                                     SystemPens.ControlText);
                ((NonVisualStyleWrapper)appointmentRenderSelWrap).UsePartialBlend = true;
                controlRenderWrap   = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.Control, SystemBrushes.Control, SystemPens.ControlText);
                bodyRenderWrap      = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.ControlLightLight, SystemBrushes.ControlLightLight, SystemPens.ControlText);
                bodyLightRenderWrap = new NonVisualStyleWrapper(SystemColors.ControlText, SystemBrushes.ControlText, SystemColors.ControlLightLight, SystemBrushes.ControlLightLight, SystemPens.Control);
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Sets the state of the <see cref="VisualStyleRenderer"/>.
 /// </summary>
 /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
 /// <param name="state">The state.</param>
 public static void SetState(this VisualStyleRenderer rnd, int state)
 {
     rnd.SetParameters(rnd.Class, rnd.Part, state);
 }
Exemplo n.º 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 = Color.FromArgb(255, 128, 0);
            Color clrEnd   = Color.FromArgb(0, 255, 0);

            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);
        }
Exemplo n.º 24
0
 public void VisualStyleRenderer_IsElementDefined_Invoke_ReturnsExpected(VisualStyleElement element, bool expected)
 {
     Assert.Equal(expected, VisualStyleRenderer.IsElementDefined(element));
 }
Exemplo n.º 25
0
 protected override void OnDrawNode(DrawTreeNodeEventArgs e)
 {
     if (e.Node.Nodes.Count == 0)
     {
         e.DrawDefault = true;
     }
     else if (VisualStyleRenderer.IsSupported)
     {
         SizeF     ef     = e.Graphics.MeasureString(e.Node.Text, this.Font);
         int       x      = (((e.Bounds.X + 5) + (e.Node.Level * 0x13)) + 0x12) + 0x10;
         int       y      = e.Bounds.Y;
         Rectangle bounds = new Rectangle(x, y, (int)ef.Width, (int)ef.Height);
         TextRenderer.DrawText(e.Graphics, e.Node.Text, this.Font, bounds, this.ForeColor);
         Pen pen = new Pen(SystemColors.GrayText)
         {
             DashStyle = DashStyle.Dot
         };
         int num2 = e.Bounds.Height / 2;
         x -= 0x10;
         e.Graphics.DrawLine(pen, new Point(x, y + num2), new Point(x + 0x10, y + num2));
         if ((e.Node.Nodes.Count > 0) && e.Node.IsExpanded)
         {
             e.Graphics.DrawLine(pen, new Point(x + 8, y + num2), new Point(x + 8, y + e.Bounds.Height));
         }
         x -= 8;
         e.Graphics.DrawLine(pen, new Point(x, y + num2), new Point(x + 8, y + num2));
         x -= 10;
         e.Graphics.DrawLine(pen, new Point(x + 5, y + num2), new Point(x + 10, y + num2));
         int num3 = y + e.Bounds.Height;
         if (e.Node.NextNode == null)
         {
             num3 = y + num2;
         }
         e.Graphics.DrawLine(pen, new Point(x + 7, y), new Point(x + 7, num3));
         VisualStyleElement opened = null;
         if (e.Node.Nodes.Count > 0)
         {
             if (e.Node.IsExpanded)
             {
                 opened = VisualStyleElement.TreeView.Glyph.Opened;
             }
             else
             {
                 opened = VisualStyleElement.TreeView.Glyph.Closed;
             }
         }
         Rectangle           rectangle8 = new Rectangle(x, y, 0x10, 0x10);
         VisualStyleRenderer renderer   = new VisualStyleRenderer(opened);
         if (e.Node.Nodes.Count > 0)
         {
             renderer.DrawBackground(e.Graphics, rectangle8);
         }
         TreeNode parent = e.Node;
         while (parent.Parent != null)
         {
             parent = parent.Parent;
             x     -= 0x13;
             if (parent.IsExpanded && (parent.NextNode != null))
             {
                 e.Graphics.DrawLine(pen, new Point(x + 7, y), new Point(x + 7, y + e.Bounds.Height));
             }
         }
     }
 }
Exemplo n.º 26
0
        public void VisualStyleRenderer_IsElementDefined_NullElementClassName_ThrowsArgumentNullException()
        {
            VisualStyleElement element = VisualStyleElement.CreateElement(null, 0, 0);

            Assert.Throws <ArgumentNullException>("className", () => VisualStyleRenderer.IsElementDefined(element));
        }
Exemplo n.º 27
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(_hotForeColour);
                }
                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;
        }
Exemplo n.º 28
0
        public void VisualStyleRenderer_SetParameters_NullElement_ThrowsArgumentNullException()
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);

            Assert.Throws <ArgumentNullException>("element", () => renderer.SetParameters(null));
        }
Exemplo n.º 29
0
    private bool EnsureRenderer()
    {
        if (!IsSupported)
            return false;

        if (renderer == null)
            renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);

        return true;
    }
Exemplo n.º 30
0
        /// <summary>
        /// Draw text without a glowing background, for use on a composition element.
        /// </summary>
        /// <param name="g">Graphics reference.</param>
        /// <param name="text">Text to be drawn.</param>
        /// <param name="font">Font to use for text.</param>
        /// <param name="bounds">Bounding area for the text.</param>
        /// <param name="state">State of the source element.</param>
        /// <param name="color"><see cref="Color"/> of the text.</param>
        /// <param name="copyBackground">Should existing background be copied into the bitmap.</param>
        /// <param name="sf">StringFormat of the memento.</param>
        public static void DrawCompositionText(Graphics g,
                                               string text,
                                               Font font,
                                               Rectangle bounds,
                                               PaletteState state,
                                               Color color,
                                               bool copyBackground,
                                               StringFormat sf)
        {
            // Get the hDC for the graphics instance and create a memory DC
            IntPtr gDC = g.GetHdc();

            try
            {
                IntPtr mDC = PI.CreateCompatibleDC(gDC);

                PI.BITMAPINFO bmi = new PI.BITMAPINFO();
                bmi.biSize        = Marshal.SizeOf(bmi);
                bmi.biWidth       = bounds.Width;
                bmi.biHeight      = -(bounds.Height);
                bmi.biCompression = 0;
                bmi.biBitCount    = 32;
                bmi.biPlanes      = 1;

                // Create a device independent bitmap and select into the memory DC
                IntPtr hDIB = PI.CreateDIBSection(gDC, bmi, 0, 0, IntPtr.Zero, 0);
                PI.SelectObject(mDC, hDIB);

                if (copyBackground)
                {
                    // Copy existing background into the bitmap
                    PI.BitBlt(mDC, 0, 0, bounds.Width, bounds.Height,
                              gDC, bounds.X, bounds.Y, 0x00CC0020);
                }

                // Select the font for use when drawing
                IntPtr hFont = font.ToHfont();
                PI.SelectObject(mDC, hFont);

                // Get renderer for the correct state
                VisualStyleRenderer renderer = new VisualStyleRenderer(state == PaletteState.Normal ? VisualStyleElement.Window.Caption.Active :
                                                                       VisualStyleElement.Window.Caption.Inactive);

                // Create structures needed for theme drawing call
                PI.RECT textBounds = new PI.RECT
                {
                    left   = 0,
                    top    = 0,
                    right  = (bounds.Right - bounds.Left),
                    bottom = (bounds.Bottom - bounds.Top)
                };
                PI.DTTOPTS dttOpts = new PI.DTTOPTS
                {
                    dwSize  = Marshal.SizeOf(typeof(PI.DTTOPTS)),
                    dwFlags = PI.DTT_COMPOSITED | PI.DTT_TEXTCOLOR,
                    crText  = ColorTranslator.ToWin32(color)
                };

                // Always draw text centered
                TextFormatFlags textFormat = TextFormatFlags.SingleLine |
                                             TextFormatFlags.HorizontalCenter |
                                             TextFormatFlags.VerticalCenter;
                ////Seb   |  TextFormatFlags.EndEllipsis;


                // Perform actual drawing
                //PI.DrawThemeTextEx(renderer.Handle,
                //                   mDC, 0, 0,
                //                   text, -1, (int)StringFormatToFlags(sf),
                //                   ref textBounds, ref dttOpts);
                PI.DrawThemeTextEx(renderer.Handle,
                                   mDC, 0, 0,
                                   text, -1, (int)textFormat,
                                   ref textBounds, ref dttOpts);

                // Copy to foreground
                PI.BitBlt(gDC,
                          bounds.Left, bounds.Top,
                          bounds.Width, bounds.Height,
                          mDC, 0, 0, 0x00CC0020);

                // Dispose of allocated objects
                PI.DeleteObject(hFont);
                PI.DeleteObject(hDIB);
                PI.DeleteDC(mDC);
            }
            catch
            {
                // ignored
            }
            finally
            {
                // Must remember to release the hDC
                g.ReleaseHdc(gDC);
            }
        }
        public void VisualStyleRenderer_IsBackgroundPartiallyTransparent_Invoke_ReturnsExpected()
        {
            var renderer = new VisualStyleRenderer("BUTTON", 0, 0);

            Assert.False(renderer.IsBackgroundPartiallyTransparent());
        }
Exemplo n.º 32
0
    /// <summary>
    /// Paints the control using the Buffered Paint API.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs<ComboBoxState> e)
    {
        if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled) {
            // draw in the vista/win7 style
            VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            Rectangle buttonBounds = ClientRectangle;
            buttonBounds.Inflate(1, 1);
            ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State));

            Rectangle clipBounds = _dropDownButtonBounds;
            clipBounds.Inflate(-2, -2);
            e.Graphics.SetClip(clipBounds);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);
        }
        else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported) {
            // draw using the visual style renderer
            ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState());
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
        }
        else {
            // draw using the legacy technique
            DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState());
        }

        OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds()));
    }
Exemplo n.º 33
0
        public static void DrawGroupBox(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
        {
            Size font_size = TextRenderer.MeasureText(groupBoxText, font);

            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr;
                Rectangle           new_bounds;

                switch (state)
                {
                case GroupBoxState.Normal:
                default:
                    vsr        = new VisualStyleRenderer(VisualStyleElement.Button.GroupBox.Normal);
                    new_bounds = new Rectangle(bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);
                    break;

                case GroupBoxState.Disabled:
                    vsr        = new VisualStyleRenderer(VisualStyleElement.Button.GroupBox.Disabled);
                    new_bounds = new Rectangle(bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 2, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 2);
                    break;
                }

                if (groupBoxText == String.Empty)
                {
                    vsr.DrawBackground(g, bounds);
                }
                else
                {
                    vsr.DrawBackgroundExcludingArea(g, new_bounds, new Rectangle(bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height));
                }

                if (textColor == Color.Empty)
                {
                    textColor = vsr.GetColor(ColorProperty.TextColor);
                }

                if (groupBoxText != String.Empty)
                {
                    TextRenderer.DrawText(g, groupBoxText, font, new Point(bounds.Left + 8, bounds.Top), textColor, flags);
                }
            }
            else
            {
                // MS has a pretty big bug when rendering the non-visual styles group box.  Instead of using the height
                // part of the bounds as height, they use it as the bottom, so the boxes are drawn in completely different
                // places.  Rather than emulate this bug, we do it correctly.  After googling for a while, I don't think
                // anyone has ever actually used this class for anything, so it should be fine.  :)
                Rectangle new_bounds = new Rectangle(bounds.Left, bounds.Top + (int)(font_size.Height / 2), bounds.Width, bounds.Height - (int)(font_size.Height / 2));

                // Don't paint over the background where we are going to put the text
                Region old_clip = g.Clip;
                g.SetClip(new Rectangle(bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);

                ControlPaint.DrawBorder3D(g, new_bounds, Border3DStyle.Etched);

                g.Clip = old_clip;

                if (groupBoxText != String.Empty)
                {
                    if (textColor == Color.Empty)
                    {
                        textColor = SystemColors.ControlText;
                    }
                    TextRenderer.DrawText(g, groupBoxText, font, new Point(bounds.Left + 8, bounds.Top), textColor, flags);
                }
            }
        }