public static void DrawBorder(Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth, ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle, Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor, int bottomWidth, ButtonBorderStyle bottomStyle)
        {
            Pen pen;
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }
            int[] numArray = new int[topWidth];
            int[] numArray2 = new int[topWidth];
            int[] numArray3 = new int[leftWidth];
            int[] numArray4 = new int[leftWidth];
            int[] numArray5 = new int[bottomWidth];
            int[] numArray6 = new int[bottomWidth];
            int[] numArray7 = new int[rightWidth];
            int[] numArray8 = new int[rightWidth];
            float num = 0f;
            float num2 = 0f;
            if (leftWidth > 0)
            {
                num = ((float) topWidth) / ((float) leftWidth);
                num2 = ((float) bottomWidth) / ((float) leftWidth);
            }
            float num3 = 0f;
            float num4 = 0f;
            if (rightWidth > 0)
            {
                num3 = ((float) topWidth) / ((float) rightWidth);
                num4 = ((float) bottomWidth) / ((float) rightWidth);
            }
            HLSColor color = new HLSColor(topColor);
            HLSColor color2 = new HLSColor(leftColor);
            HLSColor color3 = new HLSColor(bottomColor);
            HLSColor color4 = new HLSColor(rightColor);
            if (topWidth > 0)
            {
                int index = 0;
                while (index < topWidth)
                {
                    int num6 = 0;
                    if (num > 0f)
                    {
                        num6 = (int) (((float) index) / num);
                    }
                    int num7 = 0;
                    if (num3 > 0f)
                    {
                        num7 = (int) (((float) index) / num3);
                    }
                    numArray[index] = bounds.X + num6;
                    numArray2[index] = ((bounds.X + bounds.Width) - num7) - 1;
                    if (leftWidth > 0)
                    {
                        numArray3[num6] = (bounds.Y + index) + 1;
                    }
                    if (rightWidth > 0)
                    {
                        numArray7[num7] = bounds.Y + index;
                    }
                    index++;
                }
                for (int i = index; i < leftWidth; i++)
                {
                    numArray3[i] = (bounds.Y + index) + 1;
                }
                for (int j = index; j < rightWidth; j++)
                {
                    numArray7[j] = bounds.Y + index;
                }
            }
            else
            {
                for (int k = 0; k < leftWidth; k++)
                {
                    numArray3[k] = bounds.Y;
                }
                for (int m = 0; m < rightWidth; m++)
                {
                    numArray7[m] = bounds.Y;
                }
            }
            if (bottomWidth > 0)
            {
                int num12 = 0;
                while (num12 < bottomWidth)
                {
                    int num13 = 0;
                    if (num2 > 0f)
                    {
                        num13 = (int) (((float) num12) / num2);
                    }
                    int num14 = 0;
                    if (num4 > 0f)
                    {
                        num14 = (int) (((float) num12) / num4);
                    }
                    numArray5[num12] = bounds.X + num13;
                    numArray6[num12] = ((bounds.X + bounds.Width) - num14) - 1;
                    if (leftWidth > 0)
                    {
                        numArray4[num13] = ((bounds.Y + bounds.Height) - num12) - 1;
                    }
                    if (rightWidth > 0)
                    {
                        numArray8[num14] = ((bounds.Y + bounds.Height) - num12) - 1;
                    }
                    num12++;
                }
                for (int n = num12; n < leftWidth; n++)
                {
                    numArray4[n] = ((bounds.Y + bounds.Height) - num12) - 1;
                }
                for (int num16 = num12; num16 < rightWidth; num16++)
                {
                    numArray8[num16] = ((bounds.Y + bounds.Height) - num12) - 1;
                }
            }
            else
            {
                for (int num17 = 0; num17 < leftWidth; num17++)
                {
                    numArray4[num17] = (bounds.Y + bounds.Height) - 1;
                }
                for (int num18 = 0; num18 < rightWidth; num18++)
                {
                    numArray8[num18] = (bounds.Y + bounds.Height) - 1;
                }
            }
            switch (topStyle)
            {
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(topColor) {
                        DashStyle = DashStyle.Dot
                    };
                    for (int num19 = 0; num19 < topWidth; num19++)
                    {
                        graphics.DrawLine(pen, numArray[num19], bounds.Y + num19, numArray2[num19], bounds.Y + num19);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Dashed:
                    pen = new Pen(topColor) {
                        DashStyle = DashStyle.Dash
                    };
                    for (int num20 = 0; num20 < topWidth; num20++)
                    {
                        graphics.DrawLine(pen, numArray[num20], bounds.Y + num20, numArray2[num20], bounds.Y + num20);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Solid:
                    pen = new Pen(topColor) {
                        DashStyle = DashStyle.Solid
                    };
                    for (int num21 = 0; num21 < topWidth; num21++)
                    {
                        graphics.DrawLine(pen, numArray[num21], bounds.Y + num21, numArray2[num21], bounds.Y + num21);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Inset:
                {
                    float num22 = InfinityToOne(1f / ((float) (topWidth - 1)));
                    for (int num23 = 0; num23 < topWidth; num23++)
                    {
                        pen = new Pen(color.Darker(1f - (num23 * num22))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, numArray[num23], bounds.Y + num23, numArray2[num23], bounds.Y + num23);
                        pen.Dispose();
                    }
                    break;
                }
                case ButtonBorderStyle.Outset:
                {
                    float num24 = InfinityToOne(1f / ((float) (topWidth - 1)));
                    for (int num25 = 0; num25 < topWidth; num25++)
                    {
                        pen = new Pen(color.Lighter(1f - (num25 * num24))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, numArray[num25], bounds.Y + num25, numArray2[num25], bounds.Y + num25);
                        pen.Dispose();
                    }
                    break;
                }
            }
            pen = null;
            switch (leftStyle)
            {
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(leftColor) {
                        DashStyle = DashStyle.Dot
                    };
                    for (int num26 = 0; num26 < leftWidth; num26++)
                    {
                        graphics.DrawLine(pen, bounds.X + num26, numArray3[num26], bounds.X + num26, numArray4[num26]);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Dashed:
                    pen = new Pen(leftColor) {
                        DashStyle = DashStyle.Dash
                    };
                    for (int num27 = 0; num27 < leftWidth; num27++)
                    {
                        graphics.DrawLine(pen, bounds.X + num27, numArray3[num27], bounds.X + num27, numArray4[num27]);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Solid:
                    pen = new Pen(leftColor) {
                        DashStyle = DashStyle.Solid
                    };
                    for (int num28 = 0; num28 < leftWidth; num28++)
                    {
                        graphics.DrawLine(pen, bounds.X + num28, numArray3[num28], bounds.X + num28, numArray4[num28]);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Inset:
                {
                    float num29 = InfinityToOne(1f / ((float) (leftWidth - 1)));
                    for (int num30 = 0; num30 < leftWidth; num30++)
                    {
                        pen = new Pen(color2.Darker(1f - (num30 * num29))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, bounds.X + num30, numArray3[num30], bounds.X + num30, numArray4[num30]);
                        pen.Dispose();
                    }
                    break;
                }
                case ButtonBorderStyle.Outset:
                {
                    float num31 = InfinityToOne(1f / ((float) (leftWidth - 1)));
                    for (int num32 = 0; num32 < leftWidth; num32++)
                    {
                        pen = new Pen(color2.Lighter(1f - (num32 * num31))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, bounds.X + num32, numArray3[num32], bounds.X + num32, numArray4[num32]);
                        pen.Dispose();
                    }
                    break;
                }
            }
            pen = null;
            switch (bottomStyle)
            {
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(bottomColor) {
                        DashStyle = DashStyle.Dot
                    };
                    for (int num33 = 0; num33 < bottomWidth; num33++)
                    {
                        graphics.DrawLine(pen, numArray5[num33], ((bounds.Y + bounds.Height) - 1) - num33, numArray6[num33], ((bounds.Y + bounds.Height) - 1) - num33);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Dashed:
                    pen = new Pen(bottomColor) {
                        DashStyle = DashStyle.Dash
                    };
                    for (int num34 = 0; num34 < bottomWidth; num34++)
                    {
                        graphics.DrawLine(pen, numArray5[num34], ((bounds.Y + bounds.Height) - 1) - num34, numArray6[num34], ((bounds.Y + bounds.Height) - 1) - num34);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Solid:
                    pen = new Pen(bottomColor) {
                        DashStyle = DashStyle.Solid
                    };
                    for (int num35 = 0; num35 < bottomWidth; num35++)
                    {
                        graphics.DrawLine(pen, numArray5[num35], ((bounds.Y + bounds.Height) - 1) - num35, numArray6[num35], ((bounds.Y + bounds.Height) - 1) - num35);
                    }
                    pen.Dispose();
                    break;

                case ButtonBorderStyle.Inset:
                {
                    float num36 = InfinityToOne(1f / ((float) (bottomWidth - 1)));
                    for (int num37 = 0; num37 < bottomWidth; num37++)
                    {
                        pen = new Pen(color3.Lighter(1f - (num37 * num36))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, numArray5[num37], ((bounds.Y + bounds.Height) - 1) - num37, numArray6[num37], ((bounds.Y + bounds.Height) - 1) - num37);
                        pen.Dispose();
                    }
                    break;
                }
                case ButtonBorderStyle.Outset:
                {
                    float num38 = InfinityToOne(1f / ((float) (bottomWidth - 1)));
                    for (int num39 = 0; num39 < bottomWidth; num39++)
                    {
                        pen = new Pen(color3.Darker(1f - (num39 * num38))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, numArray5[num39], ((bounds.Y + bounds.Height) - 1) - num39, numArray6[num39], ((bounds.Y + bounds.Height) - 1) - num39);
                        pen.Dispose();
                    }
                    break;
                }
            }
            pen = null;
            switch (rightStyle)
            {
                case ButtonBorderStyle.None:
                    break;

                case ButtonBorderStyle.Dotted:
                    pen = new Pen(rightColor) {
                        DashStyle = DashStyle.Dot
                    };
                    for (int num40 = 0; num40 < rightWidth; num40++)
                    {
                        graphics.DrawLine(pen, ((bounds.X + bounds.Width) - 1) - num40, numArray7[num40], ((bounds.X + bounds.Width) - 1) - num40, numArray8[num40]);
                    }
                    pen.Dispose();
                    return;

                case ButtonBorderStyle.Dashed:
                    pen = new Pen(rightColor) {
                        DashStyle = DashStyle.Dash
                    };
                    for (int num41 = 0; num41 < rightWidth; num41++)
                    {
                        graphics.DrawLine(pen, ((bounds.X + bounds.Width) - 1) - num41, numArray7[num41], ((bounds.X + bounds.Width) - 1) - num41, numArray8[num41]);
                    }
                    pen.Dispose();
                    return;

                case ButtonBorderStyle.Solid:
                    pen = new Pen(rightColor) {
                        DashStyle = DashStyle.Solid
                    };
                    for (int num42 = 0; num42 < rightWidth; num42++)
                    {
                        graphics.DrawLine(pen, ((bounds.X + bounds.Width) - 1) - num42, numArray7[num42], ((bounds.X + bounds.Width) - 1) - num42, numArray8[num42]);
                    }
                    pen.Dispose();
                    return;

                case ButtonBorderStyle.Inset:
                {
                    float num43 = InfinityToOne(1f / ((float) (rightWidth - 1)));
                    for (int num44 = 0; num44 < rightWidth; num44++)
                    {
                        pen = new Pen(color4.Lighter(1f - (num44 * num43))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, ((bounds.X + bounds.Width) - 1) - num44, numArray7[num44], ((bounds.X + bounds.Width) - 1) - num44, numArray8[num44]);
                        pen.Dispose();
                    }
                    return;
                }
                case ButtonBorderStyle.Outset:
                {
                    float num45 = InfinityToOne(1f / ((float) (rightWidth - 1)));
                    for (int num46 = 0; num46 < rightWidth; num46++)
                    {
                        pen = new Pen(color4.Darker(1f - (num46 * num45))) {
                            DashStyle = DashStyle.Solid
                        };
                        graphics.DrawLine(pen, ((bounds.X + bounds.Width) - 1) - num46, numArray7[num46], ((bounds.X + bounds.Width) - 1) - num46, numArray8[num46]);
                        pen.Dispose();
                    }
                    break;
                }
                default:
                    return;
            }
        }
 private static void DrawBorderComplex(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style)
 {
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (style == ButtonBorderStyle.Inset)
     {
         HLSColor color2 = new HLSColor(color);
         Pen pen = new Pen(color2.Darker(1f));
         graphics.DrawLine(pen, bounds.X, bounds.Y, (bounds.X + bounds.Width) - 1, bounds.Y);
         graphics.DrawLine(pen, bounds.X, bounds.Y, bounds.X, (bounds.Y + bounds.Height) - 1);
         pen.Color = color2.Lighter(1f);
         graphics.DrawLine(pen, bounds.X, (bounds.Y + bounds.Height) - 1, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         graphics.DrawLine(pen, (bounds.X + bounds.Width) - 1, bounds.Y, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         pen.Color = color2.Lighter(0.5f);
         graphics.DrawLine(pen, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1));
         graphics.DrawLine(pen, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2));
         if (color.ToKnownColor() == SystemColors.Control.ToKnownColor())
         {
             pen.Color = SystemColors.ControlLight;
             graphics.DrawLine(pen, (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
             graphics.DrawLine(pen, (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
         }
         pen.Dispose();
     }
     else
     {
         bool flag = color.ToKnownColor() == SystemColors.Control.ToKnownColor();
         HLSColor color3 = new HLSColor(color);
         Pen controlDarkDark = flag ? SystemPens.ControlLightLight : new Pen(color3.Lighter(1f));
         graphics.DrawLine(controlDarkDark, bounds.X, bounds.Y, (bounds.X + bounds.Width) - 1, bounds.Y);
         graphics.DrawLine(controlDarkDark, bounds.X, bounds.Y, bounds.X, (bounds.Y + bounds.Height) - 1);
         if (flag)
         {
             controlDarkDark = SystemPens.ControlDarkDark;
         }
         else
         {
             controlDarkDark.Color = color3.Darker(1f);
         }
         graphics.DrawLine(controlDarkDark, bounds.X, (bounds.Y + bounds.Height) - 1, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         graphics.DrawLine(controlDarkDark, (bounds.X + bounds.Width) - 1, bounds.Y, (bounds.X + bounds.Width) - 1, (bounds.Y + bounds.Height) - 1);
         if (flag)
         {
             if (SystemInformation.HighContrast)
             {
                 controlDarkDark = SystemPens.ControlLight;
             }
             else
             {
                 controlDarkDark = SystemPens.Control;
             }
         }
         else
         {
             controlDarkDark.Color = color;
         }
         graphics.DrawLine(controlDarkDark, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1));
         graphics.DrawLine(controlDarkDark, (int) (bounds.X + 1), (int) (bounds.Y + 1), (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2));
         if (flag)
         {
             controlDarkDark = SystemPens.ControlDark;
         }
         else
         {
             controlDarkDark.Color = color3.Darker(0.5f);
         }
         graphics.DrawLine(controlDarkDark, (int) (bounds.X + 1), (int) ((bounds.Y + bounds.Height) - 2), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
         graphics.DrawLine(controlDarkDark, (int) ((bounds.X + bounds.Width) - 2), (int) (bounds.Y + 1), (int) ((bounds.X + bounds.Width) - 2), (int) ((bounds.Y + bounds.Height) - 2));
         if (!flag)
         {
             controlDarkDark.Dispose();
         }
     }
 }
 public static Color Light(Color baseColor, float percOfLightLight)
 {
     HLSColor color = new HLSColor(baseColor);
     return color.Lighter(percOfLightLight);
 }
 public static Color LightLight(Color baseColor)
 {
     HLSColor color = new HLSColor(baseColor);
     return color.Lighter(1f);
 }
Esempio n. 5
0
        private static void DrawBorderComplex(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException("graphics");
            }

            borderPen1.DashStyle = DashStyle.Solid;

            if (style == ButtonBorderStyle.Inset)
            { // button being pushed
                var hls = new HLSColor(color);

                // top + left
                borderPen1.Color = hls.Darker(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);

                // bottom + right
                borderPen1.Color = hls.Lighter(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y + bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 1, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);

                // Top + left inset
                borderPen1.Color = hls.Lighter(0.5f);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Y + bounds.Height - 2);

                // bottom + right inset
                if (color == SystemColors.Control)
                {
                    borderPen1.Color = SystemColors.ControlLight;
                    graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + bounds.Height - 2, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                    graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 2, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                }
            }
            else
            {
                // Standard button
                bool stockColor = color == SystemColors.Control;
                var  hls        = new HLSColor(color);

                // top + left
                borderPen1.Color = stockColor ? SystemColors.ControlLightLight : hls.Lighter(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height - 1);

                // bottom + right
                borderPen1.Color = stockColor ? SystemColors.ControlDarkDark : hls.Darker(1.0f);
                graphics.DrawLine(borderPen1, bounds.X, bounds.Y + bounds.Height - 1, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 1, bounds.Y, bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);

                // top + left inset
                if (stockColor)
                {
                    borderPen1.Color = SystemInformation.HighContrast ? SystemColors.ControlLight : SystemColors.Control;
                }
                else
                {
                    borderPen1.Color = color;
                }

                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Y + bounds.Height - 2);

                // Bottom + right inset
                borderPen1.Color = stockColor ? SystemColors.ControlDark : hls.Darker(0.5f);
                graphics.DrawLine(borderPen1, bounds.X + 1, bounds.Y + bounds.Height - 2, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                graphics.DrawLine(borderPen1, bounds.X + bounds.Width - 2, bounds.Y + 1, bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
            }
        }
        public static Color Light(this Color baseColor)
        {
            HLSColor color = new HLSColor(baseColor);

            return(color.Lighter(0.5f));
        }
Esempio n. 7
0
        public static Windows.UI.Color Light(Windows.UI.Color baseColor, float percOfLightLight)
        {
            HLSColor color = new HLSColor(baseColor);

            return(color.Lighter(percOfLightLight));
        }
        /// <devdoc>
        ///     Helper function that draws a more complex border.  This is used by DrawBorder for less common
        ///     rendering cases.  We split DrawBorder into DrawBorderSimple and DrawBorderComplex so we maximize
        ///     the % of the function call.  It is less performant to have large functions that do many things.
        /// </devdoc>
        private static void DrawBorderComplex(Graphics graphics, Rectangle bounds, Color color, ButtonBorderStyle style) {
            if (graphics == null) {
                throw new ArgumentNullException("graphics");
            }
            if (style == ButtonBorderStyle.Inset) { // button being pushed
                HLSColor hls = new HLSColor(color);

                // top + left
                Pen pen = new Pen(hls.Darker(1.0f));
                graphics.DrawLine(pen, bounds.X, bounds.Y, 
                                  bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(pen, bounds.X, bounds.Y, 
                                  bounds.X, bounds.Y + bounds.Height - 1);

                // bottom + right
                pen.Color = hls.Lighter(1.0f);
                graphics.DrawLine(pen, bounds.X, bounds.Y + bounds.Height - 1, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(pen, bounds.X + bounds.Width - 1, bounds.Y, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);

                // Top + left inset
                pen.Color = hls.Lighter(0.5f);
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                      bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                  bounds.X + 1, bounds.Y + bounds.Height - 2);

                // bottom + right inset
                if (color.ToKnownColor() == SystemColors.Control.ToKnownColor()) {
                    pen.Color = SystemColors.ControlLight;
                    graphics.DrawLine(pen, bounds.X + 1, bounds.Y + bounds.Height - 2,
                                              bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                    graphics.DrawLine(pen, bounds.X + bounds.Width - 2, bounds.Y + 1,
                                      bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                }

                pen.Dispose();
            }
            else { // Standard button
                Debug.Assert(style == ButtonBorderStyle.Outset, "Caller should have known how to use us.");
                
                bool stockColor = color.ToKnownColor() == SystemColors.Control.ToKnownColor();
                HLSColor hls = new HLSColor(color);

                // top + left
                Pen pen = stockColor ? SystemPens.ControlLightLight : new Pen(hls.Lighter(1.0f));
                graphics.DrawLine(pen, bounds.X, bounds.Y,
                                            bounds.X + bounds.Width - 1, bounds.Y);
                graphics.DrawLine(pen, bounds.X, bounds.Y, 
                                  bounds.X, bounds.Y + bounds.Height - 1);
                // bottom + right
                if (stockColor) {
                    pen = SystemPens.ControlDarkDark;
                }
                else {
                    pen.Color = hls.Darker(1.0f);
                }
                graphics.DrawLine(pen, bounds.X, bounds.Y + bounds.Height - 1, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                graphics.DrawLine(pen, bounds.X + bounds.Width - 1, bounds.Y, 
                                  bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
                // top + left inset
                if (stockColor) {
                    if (SystemInformation.HighContrast) {
                        pen = SystemPens.ControlLight;
                    }
                    else {
                        pen = SystemPens.Control;
                    }
                }
                else {
                    pen.Color = color;
                }
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                  bounds.X + bounds.Width - 2, bounds.Y + 1);
                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + 1,
                                  bounds.X + 1, bounds.Y + bounds.Height - 2);

                // Bottom + right inset                        
                if (stockColor) {
                    pen = SystemPens.ControlDark;
                }
                else {
                    pen.Color = hls.Darker(0.5f);
                }

                graphics.DrawLine(pen, bounds.X + 1, bounds.Y + bounds.Height - 2,
                                  bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                graphics.DrawLine(pen, bounds.X + bounds.Width - 2, bounds.Y + 1,
                                  bounds.X + bounds.Width - 2, bounds.Y + bounds.Height - 2);
                                  
                if (!stockColor) {
                    pen.Dispose();
                }
            }
        }
        /// <include file='doc\ControlPaint.uex' path='docs/doc[@for="ControlPaint.DrawBorder1"]/*' />
        /// <devdoc>
        ///      Draws a border of the specified style and color to the given graphics.
        /// </devdoc>
        public static void DrawBorder(Graphics graphics, Rectangle bounds,
                                      Color leftColor, int leftWidth, ButtonBorderStyle leftStyle,
                                      Color topColor, int topWidth, ButtonBorderStyle topStyle,
                                      Color rightColor, int rightWidth, ButtonBorderStyle rightStyle,
                                      Color bottomColor, int bottomWidth, ButtonBorderStyle bottomStyle) {
            // Very general, and very slow
            if (graphics == null) {
                throw new ArgumentNullException("graphics");
            }

            int[] topLineLefts = new int[topWidth];
            int[] topLineRights = new int[topWidth];
            int[] leftLineTops = new int[leftWidth];
            int[] leftLineBottoms = new int[leftWidth];
            int[] bottomLineLefts = new int[bottomWidth];
            int[] bottomLineRights = new int[bottomWidth];
            int[] rightLineTops = new int[rightWidth];
            int[] rightLineBottoms = new int[rightWidth];

            float topToLeft = 0.0f;
            float bottomToLeft = 0.0f;
            if (leftWidth > 0) {
                topToLeft = ((float)topWidth)/((float)leftWidth);
                bottomToLeft = ((float)bottomWidth)/((float)leftWidth);
            }
            float topToRight = 0.0f;
            float bottomToRight = 0.0f;
            if (rightWidth > 0) {
                topToRight = ((float)topWidth)/((float)rightWidth);
                bottomToRight = ((float)bottomWidth)/((float)rightWidth);
            }

            HLSColor topHLSColor = new HLSColor(topColor);
            HLSColor leftHLSColor = new HLSColor(leftColor);
            HLSColor bottomHLSColor = new HLSColor(bottomColor);
            HLSColor rightHLSColor = new HLSColor(rightColor);

            if (topWidth > 0) {
                int i=0;
                for (; i<topWidth; i++) {
                    int leftOffset = 0;
                    if (topToLeft > 0) {
                        leftOffset = (int)(((float)i) / topToLeft);
                    }
                    int rightOffset = 0;
                    if (topToRight > 0) {
                        rightOffset = (int)(((float)i) / topToRight);
                    }
                    topLineLefts[i] = bounds.X + leftOffset;
                    topLineRights[i] = bounds.X + bounds.Width - rightOffset - 1;
                    if (leftWidth > 0) {
                        leftLineTops[leftOffset] = bounds.Y + i + 1;
                    }
                    if (rightWidth > 0) {
                        rightLineTops[rightOffset] = bounds.Y + i;
                    }
                }
                for (int j=i; j<leftWidth; j++) {
                    leftLineTops[j] = bounds.Y + i + 1;
                }
                for (int j=i; j<rightWidth; j++) {
                    rightLineTops[j] = bounds.Y + i;
                }
            }
            else {
                for (int i=0; i<leftWidth; i++) {
                    leftLineTops[i] = bounds.Y;
                }
                for (int i=0; i<rightWidth; i++) {
                    rightLineTops[i] = bounds.Y;
                }
            }

            if (bottomWidth > 0) {
                int i=0;
                for (; i<bottomWidth; i++) {
                    int leftOffset = 0;
                    if (bottomToLeft > 0) {
                        leftOffset = (int)(((float)i) / bottomToLeft);
                    }
                    int rightOffset = 0;
                    if (bottomToRight > 0) {
                        rightOffset = (int)(((float)i) / bottomToRight);
                    }
                    bottomLineLefts[i] = bounds.X + leftOffset;
                    bottomLineRights[i] = bounds.X + bounds.Width - rightOffset - 1;
                    if (leftWidth > 0) {
                        leftLineBottoms[leftOffset] = bounds.Y + bounds.Height - i - 1;
                    }
                    if (rightWidth > 0) {
                        rightLineBottoms[rightOffset] = bounds.Y + bounds.Height - i - 1;
                    }
                }
                for (int j=i; j<leftWidth; j++) {
                    leftLineBottoms[j] = bounds.Y + bounds.Height - i - 1;
                }
                for (int j=i; j<rightWidth; j++) {
                    rightLineBottoms[j] = bounds.Y + bounds.Height - i - 1;
                }
            }
            else {
                for (int i=0; i<leftWidth; i++) {
                    leftLineBottoms[i] = bounds.Y + bounds.Height - 1;
                }
                for (int i=0; i<rightWidth; i++) {
                    rightLineBottoms[i] = bounds.Y + bounds.Height - 1;
                }
            }

            Pen pen;

            // draw top line
            switch (topStyle) {
                case ButtonBorderStyle.None:
                    // nothing
                    break;
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(topColor);
                    pen.DashStyle = DashStyle.Dot;
                    for (int i=0; i<topWidth; i++) {
                        graphics.DrawLine(pen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Dashed:
                    pen = new Pen(topColor);
                    pen.DashStyle = DashStyle.Dash;
                    for (int i=0; i<topWidth; i++) {
                        graphics.DrawLine(pen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Solid:
                    pen = new Pen(topColor);
                    pen.DashStyle = DashStyle.Solid;
                    for (int i=0; i<topWidth; i++) {
                        graphics.DrawLine(pen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Inset: {
                        float inc = InfinityToOne(1.0f/(float)(topWidth-1));
                        for (int i=0; i<topWidth; i++) {
                            pen = new Pen(topHLSColor.Darker(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);
                            pen.Dispose();
                        }
                        break;
                    }
                case ButtonBorderStyle.Outset: {
                        float inc = InfinityToOne(1.0f/(float)(topWidth-1));

                        for (int i=0; i<topWidth; i++) {
                            pen = new Pen(topHLSColor.Lighter(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, topLineLefts[i], bounds.Y + i, topLineRights[i], bounds.Y + i);
                            pen.Dispose();
                        }
                        break;
                    }
            }

            // Assertion: pen has been disposed
            pen = null;

            // draw left line
            switch (leftStyle) {
                case ButtonBorderStyle.None:
                    // nothing
                    break;
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(leftColor);
                    pen.DashStyle = DashStyle.Dot;
                    for (int i=0; i<leftWidth; i++) {
                        graphics.DrawLine(pen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Dashed:
                    pen = new Pen(leftColor);
                    pen.DashStyle = DashStyle.Dash;
                    for (int i=0; i<leftWidth; i++) {
                        graphics.DrawLine(pen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Solid:
                    pen = new Pen(leftColor);
                    pen.DashStyle = DashStyle.Solid;
                    for (int i=0; i<leftWidth; i++) {
                        graphics.DrawLine(pen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Inset: {
                        float inc = InfinityToOne(1.0f/(float)(leftWidth-1));
                        for (int i=0; i<leftWidth; i++) {
                            pen = new Pen(leftHLSColor.Darker(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);
                            pen.Dispose();
                        }
                        break;
                    }
                case ButtonBorderStyle.Outset: {
                        float inc = InfinityToOne(1.0f/(float)(leftWidth-1));
                        for (int i=0; i<leftWidth; i++) {
                            pen = new Pen(leftHLSColor.Lighter(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, bounds.X + i, leftLineTops[i], bounds.X + i, leftLineBottoms[i]);
                            pen.Dispose();
                        }
                        break;
                    }
            }

            // Assertion: pen has been disposed
            pen = null;

            // draw bottom line
            switch (bottomStyle) {
                case ButtonBorderStyle.None:
                    // nothing
                    break;
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(bottomColor);
                    pen.DashStyle = DashStyle.Dot;
                    for (int i=0; i<bottomWidth; i++) {
                        graphics.DrawLine(pen, bottomLineLefts[i], bounds.Y + bounds.Height - 1 - i, bottomLineRights[i], bounds.Y + bounds.Height - 1 - i);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Dashed:
                    pen = new Pen(bottomColor);
                    pen.DashStyle = DashStyle.Dash;
                    for (int i=0; i<bottomWidth; i++) {
                        graphics.DrawLine(pen, bottomLineLefts[i], bounds.Y + bounds.Height - 1 - i, bottomLineRights[i], bounds.Y + bounds.Height - 1 - i);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Solid:
                    pen = new Pen(bottomColor);
                    pen.DashStyle = DashStyle.Solid;
                    for (int i=0; i<bottomWidth; i++) {
                        graphics.DrawLine(pen, bottomLineLefts[i], bounds.Y + bounds.Height - 1 - i, bottomLineRights[i], bounds.Y + bounds.Height - 1 - i);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Inset: {
                        float inc = InfinityToOne(1.0f/(float)(bottomWidth-1));
                        for (int i=0; i<bottomWidth; i++) {
                            pen = new Pen(bottomHLSColor.Lighter(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, bottomLineLefts[i], bounds.Y + bounds.Height - 1 - i, bottomLineRights[i], bounds.Y + bounds.Height - 1 - i);
                            pen.Dispose();
                        }
                        break;
                    }
                case ButtonBorderStyle.Outset: {
                        float inc = InfinityToOne(1.0f/(float)(bottomWidth-1));

                        for (int i=0; i<bottomWidth; i++) {
                            pen = new Pen(bottomHLSColor.Darker(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, bottomLineLefts[i], bounds.Y + bounds.Height - 1 - i, bottomLineRights[i], bounds.Y + bounds.Height - 1 - i);
                            pen.Dispose();
                        }
                        break;
                    }
            }

            // Assertion: pen has been disposed
            pen = null;

            // draw right line
            switch (rightStyle) {
                case ButtonBorderStyle.None:
                    // nothing
                    break;
                case ButtonBorderStyle.Dotted:
                    pen = new Pen(rightColor);
                    pen.DashStyle = DashStyle.Dot;
                    for (int i=0; i<rightWidth; i++) {
                        graphics.DrawLine(pen, bounds.X + bounds.Width - 1 - i, rightLineTops[i], bounds.X + bounds.Width - 1 - i, rightLineBottoms[i]);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Dashed:
                    pen = new Pen(rightColor);
                    pen.DashStyle = DashStyle.Dash;
                    for (int i=0; i<rightWidth; i++) {
                        graphics.DrawLine(pen, bounds.X + bounds.Width - 1 - i, rightLineTops[i], bounds.X + bounds.Width - 1 - i, rightLineBottoms[i]);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Solid:
                    pen = new Pen(rightColor);
                    pen.DashStyle = DashStyle.Solid;
                    for (int i=0; i<rightWidth; i++) {
                        graphics.DrawLine(pen, bounds.X + bounds.Width - 1 - i, rightLineTops[i], bounds.X + bounds.Width - 1 - i, rightLineBottoms[i]);
                    }
                    pen.Dispose();
                    break;
                case ButtonBorderStyle.Inset: {
                        float inc = InfinityToOne(1.0f/(float)(rightWidth-1));
                        for (int i=0; i<rightWidth; i++) {
                            pen = new Pen(rightHLSColor.Lighter(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, bounds.X + bounds.Width - 1 - i, rightLineTops[i], bounds.X + bounds.Width - 1 - i, rightLineBottoms[i]);
                            pen.Dispose();
                        }
                        break;
                    }
                case ButtonBorderStyle.Outset: {
                        float inc = InfinityToOne(1.0f/(float)(rightWidth-1));

                        for (int i=0; i<rightWidth; i++) {
                            pen = new Pen(rightHLSColor.Darker(1.0f - ((float)i)*inc));
                            pen.DashStyle = DashStyle.Solid;
                            graphics.DrawLine(pen, bounds.X + bounds.Width - 1 - i, rightLineTops[i], bounds.X + bounds.Width - 1 - i, rightLineBottoms[i]);
                            pen.Dispose();
                        }

                        break;
                    }
            }
        }