Ejemplo n.º 1
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            Rectangle rect       = new Rectangle(0, 0, this.Width, this.Height);         // e.ClipRectangle;
            Rectangle borderrect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); // e.ClipRectangle;

            // Draw background
            Color gradStartColor;
            Color gradEndColor;

            if (_gradientToogleColors == false)
            {
                gradStartColor = _gradientStartColor;
                gradEndColor   = _gradientEndColor;
            }
            else
            {
                gradStartColor = _gradientEndColor;
                gradEndColor   = _gradientStartColor;
            }

            if (_gradientUseSolid == false)
            {
                if (_gradientUseBlend == false)
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(rect,
                                                                               gradStartColor,
                                                                               gradEndColor,
                                                                               GradientDirection))
                    {
                        e.Graphics.FillRectangle(brush, rect);
                    }
                }
                else
                {
                    DrawingMethods.DrawGradient(e.Graphics, rect, gradStartColor, gradEndColor, 90F, false, Color.White, 0);
                }
            }
            else
            //Solid Color
            {
                using (Brush brush = new SolidBrush(GradientSolidColour))
                {
                    e.Graphics.FillRectangle(brush, rect);
                }
            }

            if (this._borderWidth > 0)
            {
                e.Graphics.DrawRectangle(new Pen(Color.FromArgb(180, this._borderColor), _borderWidth), borderrect);
            }
        }
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      System.Windows.Forms.DataGridViewPaintParts paintParts)
        {
            Single progressVal;

            try
            {
                progressVal = Conversions.ToSingle(value);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                progressVal = 0;
            }

            float percentage = (float)(progressVal / 100);
            Brush backBrush  = new SolidBrush(cellStyle.BackColor);
            Brush foreBrush  = new SolidBrush(cellStyle.ForeColor);

            // Call the base Class method to paint the default cell appearance.
            base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle,
                       paintParts);

            if (percentage > 0.0)
            {
                if (percentage > 1)
                {
                    percentage = 1;
                }
                // Draw the progress bar and the text
                Rectangle rect = new Rectangle(cellBounds.X + 1, cellBounds.Y + 1, Convert.ToInt32((percentage * cellBounds.Width - 3)), cellBounds.Height - 3);
                DrawingMethods.DrawGradient(g, rect, Color.FromArgb(205, 255, 205), Color.FromArgb(10, 209, 48), 90F, false, Color.White, 0);
                g.DrawRectangle(new Pen(Color.FromArgb(28, 220, 56)), rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
                //g.FillRectangle(New SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4)
                g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreBrush, cellBounds.X + 6, cellBounds.Y + 4);
            }
            else
            {
                //draw the text
                if ((this.DataGridView.CurrentCell != null) && this.DataGridView.CurrentCell.RowIndex == rowIndex)
                {
                    g.DrawString(progressVal.ToString() + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6, cellBounds.Y + 4);
                }
                else
                {
                    g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreBrush, cellBounds.X + 6, cellBounds.Y + 4);
                }
            }
        }
Ejemplo n.º 3
0
        private void InternalRenderer(ref Graphics g, ref Rectangle rect)
        {
            //set colors
            if (_persistentColours == false)
            {
                //init color values
                if (_useStyledColours == true)
                {
                    _gradientStartColour  = Color.FromArgb(255, 246, 215);
                    _gradientEndColour    = Color.FromArgb(255, 213, 77);
                    _gradientMiddleColour = Color.FromArgb(252, 224, 133);
                }
                else
                {
                    _gradientStartColour  = _palette.ColorTable.StatusStripGradientBegin;
                    _gradientEndColour    = _palette.ColorTable.OverflowButtonGradientEnd;
                    _gradientMiddleColour = _palette.ColorTable.StatusStripGradientEnd;
                }
            }


            //draw
            DrawingMethods.DrawGradient(g, rect, _gradientStartColour, _gradientEndColour, 90F, _enableSelectionBorder, _gradientMiddleColour, 1);
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            int tmpShadowOffSet      = Math.Min(Math.Min(_shadowOffSet, this.Width - 2), this.Height - 2);
            int tmpSoundCornerRadius = Math.Min(Math.Min(_roundCornerRadius, this.Width - 2), this.Height - 2);

            if (this.Width > 1 && this.Height > 1)
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                Rectangle rect = new Rectangle(0, 0, this.Width - tmpShadowOffSet - 1,
                                               this.Height - tmpShadowOffSet - 1);

                Rectangle rectShadow = new Rectangle(tmpShadowOffSet, tmpShadowOffSet,
                                                     this.Width - tmpShadowOffSet - 1, this.Height - tmpShadowOffSet - 1);

                GraphicsPath graphPathShadow = GetRoundPath(rectShadow, tmpSoundCornerRadius);
                GraphicsPath graphPath       = GetRoundPath(rect, tmpSoundCornerRadius);

                if (tmpSoundCornerRadius > 0)
                {
                    using (PathGradientBrush gBrush = new PathGradientBrush(graphPathShadow))
                    {
                        gBrush.WrapMode = WrapMode.Clamp;
                        ColorBlend colorBlend = new ColorBlend(3);
                        colorBlend.Colors = new Color[] { Color.Transparent,
                                                          Color.FromArgb(180, Color.DimGray),
                                                          Color.FromArgb(180, Color.DimGray) };

                        colorBlend.Positions = new float[] { 0f, .1f, 1f };

                        gBrush.InterpolationColors = colorBlend;
                        e.Graphics.FillPath(gBrush, graphPathShadow);
                    }
                }

                // Draw backgroup
                Color gradStartColor;
                Color gradEndColor;
                if (_gradientToogleColors == false)
                {
                    gradStartColor = _gradientStartColor;
                    gradEndColor   = _gradientEndColor;
                }
                else
                {
                    gradStartColor = _gradientEndColor;
                    gradEndColor   = _gradientStartColor;
                }


                if (_gradientUseBlend == false)
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(rect,
                                                                               gradStartColor,
                                                                               gradEndColor,
                                                                               GradientDirection))
                    {
                        e.Graphics.FillPath(brush, graphPath);
                    }
                }
                else
                {
                    DrawingMethods.DrawGradient(e.Graphics, rect, gradStartColor, gradEndColor, 90F, false, Color.White, 0);
                }

                if (this._borderWidth > 0)
                {
                    e.Graphics.DrawPath(new Pen(Color.FromArgb(180, this._borderColor), _borderWidth), graphPath);
                }
                // Draw Image
                if (_image != null)
                {
                    e.Graphics.DrawImageUnscaled(_image, _imageLocation);
                }
            }
        }
Ejemplo n.º 5
0
        protected void ODrawItem(DrawItemEventArgs e)
        {
            Rectangle rect = e.Bounds;
            Graphics  g    = e.Graphics;

            //DDL fix
            if (e.Index == -1)
            {
                return;
            }

            //ClearType
            try
            {
                e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

            if (_palette == null)
            {
                EventArgs Ev = new EventArgs();
                ThisGlobalPaletteChanged(this, Ev);
            }

            //set colors
            if (_persistentColors == false)
            {
                //init color values
                if (_useStyledColors == true)
                {
                    _gradientStartColor = Color.FromArgb(255, 246, 215);
                    _gradientEndColor   = Color.FromArgb(255, 213, 77);
                }
                else
                {
                    _gradientStartColor = _palette.ColorTable.StatusStripGradientBegin;
                    _gradientEndColor   = _palette.ColorTable.OverflowButtonGradientEnd;
                }
            }

            //BackColors
            Color gradStartColor = _gradientStartColor;
            Color gradEndColor   = _gradientEndColor;
            Color textColor      = _palette.ColorTable.StatusStripText;

            // Retrieve the item font. If the item font has not been set,
            // use the ComboBox font.
            Font itemFont = e.Font;

            if (itemFont == null)
            {
                itemFont = this.Font;
            }

            // Draw the background of the item.
            e.DrawBackground();

            // Draw each string in the array, using a different size, color,
            // and font for each item.

            string str = (string)this.Items[e.Index];

            if (!Enabled)
            {
                e.Graphics.DrawString(str, itemFont, new SolidBrush(SystemColors.GrayText), e.Bounds);
            }
            else
            {
                e.Graphics.DrawString(str, itemFont, new SolidBrush(this.ForeColor), e.Bounds);
            }

            if ((e.State & DrawItemState.Selected) != 0)
            {
                //DrawingMethods.DrawBlendGradient(e.Graphics, e.Bounds, gradStartColor, gradEndColor, gradMiddleColor, 90F);
                DrawingMethods.DrawGradient(g, e.Bounds, gradStartColor, gradEndColor, 90F, false, Color.White, 0);
                e.Graphics.DrawString(str, itemFont, new SolidBrush(textColor), e.Bounds);
                e.DrawFocusRectangle();
            }

            // Draw the focus rectangle if the mouse hovers over an item.
            e.DrawFocusRectangle();
        }
Ejemplo n.º 6
0
        protected override void OnDrawNode(DrawTreeNodeEventArgs e)
        {
            try
            {
                //init expanded, collapsed, item values
                string expanded  = ">>";
                string collapsed = "<<";
                string item      = " ";

                Image exp;
                Image col;
                if (_enableVistaSigns == true)
                {
                    exp = ilSigns.Images[2];
                    col = ilSigns.Images[3];
                }
                else
                {
                    exp = ilSigns.Images[0];
                    col = ilSigns.Images[1];
                }


                //node font color
                Brush nodeTextColor  = new SolidBrush(_nodeTextColor); //new SolidBrush(_palette.ColorTable.ToolStripText);
                Brush nodeFocusColor = new SolidBrush(_nodeFocusColor);

                Graphics  g    = e.Graphics;
                Rectangle rect = e.Bounds;

                //ClearType
                try
                {
                    e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }

                // for background and for expanded, collapsed indicator
                Rectangle bgnrect = e.Bounds;
                bgnrect.Height -= 1;
                bgnrect.Width  -= 1;


                Color gradStartColor = _gradientStartColor;
                Color gradEndColor   = _gradientEndColor;

                //set colors
                if (_persistentColors == false)
                {
                    //init color values
                    if (_useStyledColors == true)
                    {
                        gradStartColor = _gradientStartColorStyled;
                        gradEndColor   = _gradientEndColorStyled;
                    }
                    else
                    {
                        gradStartColor = _gradientStartColor;
                        gradEndColor   = _gradientEndColor;
                    }
                }

                //BackColors



                //TreeNodeStates stat = e.State;
                //Console.Write(stat);

                // Draw the background and node text for a selected node.
                if (((e.State & TreeNodeStates.Selected) != 0) || ((e.State & TreeNodeStates.Focused) != 0) || ((e.State & TreeNodeStates.Checked) != 0))
                {
                    // Draw the background of the selected node. The NodeBounds
                    // method makes the highlight rectangle large enough to
                    // include the text of a node tag, if one is present.

                    using (LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, gradStartColor, gradEndColor, LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(Brushes.White, rect);
                    }

                    if (_flatDesign)
                    {
                        g.FillRectangle(new SolidBrush(_flatDesignColor), rect);
                    }
                    else
                    {
                        DrawingMethods.DrawGradient(g, bgnrect, gradStartColor, gradEndColor, 90F, _enableSelectionBorder, gradEndColor, 1);
                    }
                    //DrawingMethods.DrawBlendGradient(g, rect, gradStartColor, gradEndColor, gradMiddleColor, 90F);

                    // Retrieve the node font. If the node font has not been set,
                    // use the TreeView font.
                    Font nodeFont = e.Node.NodeFont;
                    if (nodeFont == null)
                    {
                        nodeFont = this.Font;
                    }


                    //if root node, less offset
                    if (e.Node.Level != 0)
                    {
                        //others
                        //progress by 19 starting with 41
                        rect.Offset(41 + 19 * (e.Node.Level - 1), 0);
                        bgnrect.Offset(41 + 19 * (e.Node.Level - 1) - 18, 0);

                        //if (e.Node.Level == 1) rect.Offset(41, 0);
                        //if (e.Node.Level == 2) rect.Offset(60, 0);
                        //if (e.Node.Level == 3) rect.Offset(79, 0);
                        //if (e.Node.Level == 4) rect.Offset(98, 0);
                    }
                    else
                    {
                        //root
                        rect.Offset(22, 0);
                        bgnrect.Offset(22 - 18, 0);
                    }


                    //expanded, collapsed, item? --> Draw Indicator
                    if (e.Node.Nodes.Count > 0)
                    {
                        if (e.Node.IsExpanded)              //Expanded
                        {
                            if (_enableVisualSigns == true) //image or string?
                            {
                                g.DrawImage(col, bgnrect.X - 1, bgnrect.Y, 16, 16);
                            }
                            else
                            {
                                g.DrawString(collapsed, nodeFont, nodeTextColor, bgnrect);
                            }
                        }
                        else // Collapsed
                        {
                            if (_enableVisualSigns == true)
                            {
                                g.DrawImage(exp, bgnrect.X - 1, bgnrect.Y, 16, 16);
                            }
                            else
                            {
                                g.DrawString(expanded, nodeFont, nodeTextColor, bgnrect);
                            }
                        }
                    }
                    else //Item
                    {
                        g.DrawString(item, nodeFont, nodeTextColor, bgnrect);
                    }

                    //CheckBox present?
                    if (this.CheckBoxes == true)
                    {
                        //string CheckState = "V";
                        Image Check;
                        if (e.Node.Checked == true)
                        {
                            //CheckState = "V";
                            if (_enableVistaCheckBoxes == true)
                            {
                                Check = ilCheckBoxes.Images[3];
                            }
                            else
                            {
                                Check = ilCheckBoxes.Images[1];
                            }
                        }
                        else
                        {
                            //CheckState = "O";
                            if (_enableVistaCheckBoxes == true)
                            {
                                Check = ilCheckBoxes.Images[2];
                            }
                            else
                            {
                                Check = ilCheckBoxes.Images[0];
                            }
                        }

                        //vista Pixel fix
                        if (Utility.IsVista() == true)
                        {
                            rect.Offset(-2, -1);
                        }

                        //e.Graphics.DrawString(CheckState, this.Font, new SolidBrush(textColor), rect);
                        g.DrawImage(Check, rect.X, rect.Y, 16, 16);
                        rect.Offset(16, 0);

                        //vista Pixel fix
                        if (Utility.IsVista() == true)
                        {
                            rect.Offset(-1, 1);
                        }
                    }

                    //Picture Present?
                    if (this.ImageList != null && e.Node.ImageIndex >= 0 && e.Node.ImageIndex < ImageList.Images.Count)
                    {
                        this.ImageList.Draw(g, rect.X, rect.Y + 0, 16, 16, e.Node.ImageIndex);
                        rect.Offset(19, 0);
                    }
                    else
                    {
                        if (this.ImageList != null)
                        {
                            this.ImageList.Draw(g, rect.X, rect.Y + 0, 16, 16, this.ImageIndex);
                            rect.Offset(19, 0);
                        }
                    }

                    //ofset for aligning the text
                    rect.Offset(0, 1);

                    // Draw the node text.
                    g.DrawString(e.Node.Text, nodeFont, nodeTextColor, rect);
                }


                // Use the default background and node text.
                else
                {
                    e.DrawDefault = true;
                }

                // If a node tag is present, draw its string representation
                // to the right of the label text.
                if (e.Node.Tag != null)
                {
                    e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont,
                                          nodeTextColor, e.Bounds.Right + 2, e.Bounds.Top);
                }

                // If the node has focus, draw the focus rectangle large, making
                // it large enough to include the text of the node tag, if present.
                if ((e.State & TreeNodeStates.Focused) != 0)
                {
                    using (Pen focusPen = new Pen(nodeFocusColor))
                    {
                        focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                        Rectangle focusBounds = NodeBounds(e.Node);
                        focusBounds.Size = new Size(focusBounds.Width - 1,
                                                    focusBounds.Height - 2);
                        //uncomment for focus area
                        if (_drawFocus == true)
                        {
                            e.Graphics.DrawRectangle(focusPen, focusBounds);
                        }
                    }
                }
                nodeTextColor.Dispose();
                nodeFocusColor.Dispose();
            }

            catch
            {
            }
        }