コード例 #1
0
ファイル: Section.cs プロジェクト: kkmeteor/StudyProjects
        private void DrawHeader(Graphics g, Color color)
        {
            DrawBackGround(g, new Rectangle(_x, _y, _w, DefaultConfigs.SECTIONHEADERHEIGHT), color);
            using (Brush b = new SolidBrush(color))
            {
                //g.FillRectangle(b, _x, _y, _w, DefaultConfigs.SECTIONHEADERHEIGHT);

                Color backlight      = ControlPaint.Light(SystemColors.Control);
                Color backlightlight = ControlPaint.LightLight(SystemColors.Control);
                Color backdark       = ControlPaint.Dark(SystemColors.Control);
                Color backdarkdark   = ControlPaint.DarkDark(SystemColors.Control);

                using (Brush brushlight = new SolidBrush(backlight))
                    using (Brush brushdark = new SolidBrush(backdark))
                        using (Pen penlight = new Pen(brushlight, 1))
                            using (Pen pendark = new Pen(brushdark, 1))
                                using (Brush brushlightlight = new SolidBrush(backlightlight))
                                    using (Brush brushdarkdark = new SolidBrush(backdarkdark))
                                        using (Pen penlightlight = new Pen(brushlightlight, 1))
                                            using (Pen pendarkdark = new Pen(brushdarkdark, 1))
                                            {
                                                g.DrawLine(pendark, _x, _y, _x + _w - 2, _y);
                                                g.DrawLine(pendark, _x, _y, _x, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 2);
                                                g.DrawLine(pendarkdark, _x + 1, _y + 1, _x + _w - 3, _y + 1);
                                                g.DrawLine(pendarkdark, _x + 1, _y + 1, _x + 1, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 3);

                                                g.DrawLine(penlightlight, _x, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 1, _x + _w - 1, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 1);
                                                g.DrawLine(penlightlight, _x + _w - 1, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 1, _x + _w - 1, _y);
                                                g.DrawLine(penlight, _x + 1, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 2, _x + _w - 2, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 2);
                                                g.DrawLine(penlight, _x + _w - 2, _y + DefaultConfigs.SECTIONHEADERHEIGHT - 2, _x + _w - 2, _y + 1);
                                            }
            }
        }
コード例 #2
0
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (m.Msg == WM_PAINT)
            {
                Graphics g = Graphics.FromHwnd(Handle);
                g.Clear(BackColor);
                var       darkPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 5);
                Rectangle bounds  = new Rectangle(0, 0, Width, Height);
                g.DrawRectangle(darkPen, bounds);
                Rectangle dropdownBox = new Rectangle(bounds.Right - bounds.Height, bounds.Y, bounds.Height, bounds.Height);
                if (MouseButtons == MouseButtons.Left)
                {
                    g.FillRectangle(new SolidBrush(ControlPaint.DarkDark(BackColor)), dropdownBox);
                }
                g.DrawRectangle(darkPen, dropdownBox);
                var ArrowPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 2);
                g.DrawLine(ArrowPen, dropdownBox.Left + dropdownBox.Width / 6,
                           dropdownBox.Top + dropdownBox.Height / 3,
                           dropdownBox.Left + dropdownBox.Width / 2,
                           dropdownBox.Top + dropdownBox.Height / 3 * 2);

                g.DrawLine(ArrowPen, dropdownBox.Right - dropdownBox.Width / 6,
                           dropdownBox.Top + dropdownBox.Height / 3,
                           dropdownBox.Right - dropdownBox.Width / 2,
                           dropdownBox.Top + dropdownBox.Height / 3 * 2);
                if (SelectedIndex >= 0)
                {
                    TextRenderer.DrawText(g, Items[SelectedIndex].ToString(), Font, new Rectangle(0, 0, bounds.Width - bounds.Height, bounds.Height), BackColor.TextColor());
                }
            }
        }
        public void ControlPaint_DrawBorder_Inset_Rendering()
        {
            using var emf = new EmfScope();
            DeviceContextState state = new DeviceContextState(emf);

            using Graphics graphics = Graphics.FromHdc((IntPtr)emf.HDC);

            Rectangle bounds = new Rectangle(10, 10, 10, 10);

            ControlPaint.DrawBorder(graphics, bounds, Color.Gray, ButtonBorderStyle.Inset);

            // For whatever reason GDI+ renders as polylines scaled 16x with a 1/16th world transform applied.
            // For test readability we'll transform the points from our coordinates to the logical coordinates.
            Matrix3x2 oneSixteenth = Matrix3x2.CreateScale(0.0625f);
            Matrix3x2 times16      = Matrix3x2.CreateScale(16.0f);

            // This is the default pen style GDI+ renders polylines with
            Gdi32.PS penStyle = Gdi32.PS.SOLID | Gdi32.PS.JOIN_ROUND | Gdi32.PS.COSMETIC | Gdi32.PS.ENDCAP_FLAT
                                | Gdi32.PS.JOIN_MITER | Gdi32.PS.GEOMETRIC;

            emf.Validate(
                state,
                // Top
                Validate.Polyline16(
                    bounds: null,
                    PointArray(times16, 10, 10, 19, 10),
                    State.Pen(16, ControlPaint.DarkDark(Color.Gray), penStyle),
                    State.Transform(oneSixteenth)),
                // Left
                Validate.Polyline16(
                    bounds: null,
                    PointArray(times16, 10, 10, 10, 19),
                    State.Pen(16, ControlPaint.DarkDark(Color.Gray), penStyle),
                    State.Transform(oneSixteenth)),
                // Bottom
                Validate.Polyline16(
                    bounds: null,
                    PointArray(times16, 10, 19, 19, 19),
                    State.Pen(16, ControlPaint.LightLight(Color.Gray), penStyle),
                    State.Transform(oneSixteenth)),
                // Right
                Validate.Polyline16(
                    bounds: null,
                    PointArray(times16, 19, 10, 19, 19),
                    State.Pen(16, ControlPaint.LightLight(Color.Gray), penStyle),
                    State.Transform(oneSixteenth)),
                // Top inset
                Validate.Polyline16(
                    bounds: null,
                    PointArray(times16, 11, 11, 18, 11),
                    State.Pen(16, ControlPaint.Light(Color.Gray), penStyle),
                    State.Transform(oneSixteenth)),
                // Left inset
                Validate.Polyline16(
                    bounds: null,
                    PointArray(times16, 11, 11, 11, 18),
                    State.Pen(16, ControlPaint.Light(Color.Gray), penStyle),
                    State.Transform(oneSixteenth))
                );
        }
コード例 #4
0
ファイル: ResizeBar.cs プロジェクト: jugstalt/gViewGisOS
        protected override void OnPaint(PaintEventArgs e)
        {
            Color backColor = this.BackColor;

            switch (this.Dock)
            {
            case DockStyle.Right:
                using (Pen penD = new Pen(ControlPaint.Dark(backColor)),
                       penDD = new Pen(ControlPaint.DarkDark(backColor)))
                {
                    e.Graphics.DrawLine(penD, this.Width - 2, 0, this.Width - 2, this.Height);
                    e.Graphics.DrawLine(penDD, this.Width - 1, 0, this.Width - 1, this.Height);
                }
                break;

            case DockStyle.Left:
                using (Pen penLL = new Pen(ControlPaint.LightLight(backColor)))
                    e.Graphics.DrawLine(penLL, 1, 0, 1, this.Height);
                break;

            case DockStyle.Bottom:
                using (Pen penD = new Pen(ControlPaint.Dark(backColor)),
                       penDD = new Pen(ControlPaint.DarkDark(backColor)))
                {
                    e.Graphics.DrawLine(penD, 0, this.Height - 2, this.Width, this.Height - 2);
                    e.Graphics.DrawLine(penDD, 0, this.Height - 1, this.Width, this.Height - 1);
                }
                break;

            case DockStyle.Top:
                using (Pen penLL = new Pen(ControlPaint.LightLight(backColor)))
                    e.Graphics.DrawLine(penLL, 0, 1, this.Width, 1);
                break;
            }
        }
コード例 #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            var       g       = e.Graphics;
            var       darkPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 5);
            Rectangle bounds  = new Rectangle(-3, -3, Width + 3, Height + 3);

            g.DrawRectangle(darkPen, bounds);
            Rectangle dropdownBox = new Rectangle(bounds.Right - bounds.Height, bounds.Y, bounds.Height, bounds.Height);

            if (MouseButtons == MouseButtons.Left)
            {
                g.FillRectangle(new SolidBrush(ControlPaint.DarkDark(BackColor)), dropdownBox);
            }
            g.DrawRectangle(darkPen, dropdownBox);
            var ArrowPen = new Pen(ControlPaint.Dark(BackColor, 0.01f), 2);

            g.DrawLine(ArrowPen, dropdownBox.Left + dropdownBox.Width / 6,
                       dropdownBox.Top + dropdownBox.Height / 3,
                       dropdownBox.Left + dropdownBox.Width / 2,
                       dropdownBox.Top + dropdownBox.Height / 3 * 2);

            g.DrawLine(ArrowPen, dropdownBox.Right - dropdownBox.Width / 6,
                       dropdownBox.Top + dropdownBox.Height / 3,
                       dropdownBox.Right - dropdownBox.Width / 2,
                       dropdownBox.Top + dropdownBox.Height / 3 * 2);
            TextRenderer.DrawText(e.Graphics, Items[SelectedIndex].ToString(), Font, new Rectangle(0, 0, bounds.Width - bounds.Height, bounds.Height), BackColor.TextColor());
        }
コード例 #6
0
ファイル: QueueUsageControl.cs プロジェクト: git-thinh/core
        public static Bitmap GenerateItemImage(string text, Color color, int width, int height, Font font)
        {
            //Debug.WriteLine("GenerateItemImage");

            Rectangle rc        = new Rectangle(0, 0, width, height);
            Bitmap    itemImage = new Bitmap(rc.Width, rc.Height);

            /// Create button
            rc.Inflate(-3, -3);
            GraphicsPath path1 = GetPath(rc, 10);

            rc.Inflate(0, 6);
            LinearGradientBrush br1 = new LinearGradientBrush(rc, color, Color.White, LinearGradientMode.Vertical);

            rc.Inflate(0, -6);

            /// Create shadow
            Rectangle rc2 = rc;

            rc2.Offset(8, 8);
            GraphicsPath      path2 = GetPath(rc2, 20);
            PathGradientBrush br2   = new PathGradientBrush(path2);

            br2.CenterColor    = ControlPaint.DarkDark(Color.Silver);
            br2.SurroundColors = new Color[] { Color.White };

            /// Create bubble
            Rectangle rc3 = rc;

            rc3.Inflate(-15, -rc.Height / 3);
            rc3.Y = rc3.Y - 2;
            //rc3.Height = rc3.Height;
            GraphicsPath        path3 = GetPath(rc3, rc3.Height);
            LinearGradientBrush br3   = new LinearGradientBrush(rc3, Color.FromArgb(255, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical);

            itemImage = new Bitmap(width - 2, height);
            Graphics g = Graphics.FromImage(itemImage);

            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.FillPath(br2, path2);
            g.FillPath(br1, path1);
            g.FillPath(br3, path3);

            //SizeF size = g.MeasureString(text, font);
            //int fontHeight = (int)size.Height + 5;

            //g.DrawString(
            //    text,
            //    font,
            //    Brushes.Black,
            //    new RectangleF((rc.Width - size.Width) / 2, 2, width, fontHeight));

            return(itemImage);
        }
コード例 #7
0
        private void SetForeColor()
        {
            int r = btnFogColor.BackColor.R;
            int g = btnFogColor.BackColor.G;
            int b = btnFogColor.BackColor.B;

            btnFogColor.ForeColor =
                btnFogColor.BackColor.GetBrightness() < 0.5f
                    ? ControlPaint.LightLight(Color.FromArgb(r, g, b))
                    : ControlPaint.DarkDark(Color.FromArgb(r, g, b));
        }
コード例 #8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            int offsetX = (int)Math.Min(10, Math.Max(2, this.Width * 0.05));
            int offsetY = (int)Math.Min(10, Math.Max(2, this.Height * 0.05));

            innerWidth  = this.Width - offsetX * 2;
            innerHeight = this.Height - offsetY * 2;

            Graphics g = e.Graphics;

            Color col1  = ControlPaint.LightLight(this.BackColor);
            Color col2  = ControlPaint.DarkDark(this.BackColor);
            Brush brush = new LinearGradientBrush(Point.Empty, new Point(0, this.Height), col2, col1);

            // background shadding
            Rectangle rec = this.ClientRectangle;

            g.FillEllipse(brush, rec);

            GraphicsPath gp = new GraphicsPath();

            // 10% increase in size
            Rectangle tmp = new Rectangle(offsetX, offsetY, innerWidth, innerHeight);

            tmp.Inflate(innerWidth / 10, innerHeight / 10);
            gp.AddEllipse(tmp);

            PathGradientBrush brush2 = new PathGradientBrush(gp);

            brush2.CenterPoint = new Point((innerWidth + offsetX) / 2 + 1, innerHeight * 3 / 4);
            brush2.CenterColor = Value?this.ForeColor:this.offColor;

            brush2.SurroundColors = new Color[] { Color.Black };
            brush2.FocusScales    = new PointF(0.2f, 0.2f);
            brush2.WrapMode       = WrapMode.TileFlipXY;

            rec = new Rectangle(offsetX, offsetY, innerWidth, innerHeight);
            g.FillEllipse(brush2, rec);


            LinearGradientBrush highLight = new LinearGradientBrush(
                new Point(0, innerHeight / 25 + offsetY),
                new Point(0, innerHeight / 25 + offsetY + innerHeight * 4 / 10),
                Color.FromArgb(200, Color.White), Color.Transparent);

            g.FillEllipse(highLight,
                          new Rectangle(
                              innerWidth / 5 + offsetX, innerHeight / 25 + offsetY,
                              innerWidth * 6 / 10, innerHeight * 4 / 10)
                          );
            base.OnPaint(e);
        }
コード例 #9
0
 public static void DrawPlainSunken(Graphics g,
                                    Rectangle boxRect,
                                    Color baseColor)
 {
     using (Pen lighlight = new Pen(ControlPaint.LightLight(baseColor)),
            dark = new Pen(ControlPaint.DarkDark(baseColor)))
     {
         g.DrawLine(dark, boxRect.Left, boxRect.Bottom, boxRect.Left, boxRect.Top);
         g.DrawLine(dark, boxRect.Left, boxRect.Top, boxRect.Right, boxRect.Top);
         g.DrawLine(lighlight, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
         g.DrawLine(lighlight, boxRect.Right, boxRect.Bottom, boxRect.Left, boxRect.Bottom);
     }
 }
コード例 #10
0
ファイル: ResizeBar.cs プロジェクト: zhaoyin/officeOBA
        /// <summary>
        /// Raises the Paint event.
        /// </summary>
        /// <param name="e">A PaintEventArgs that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            Color backColor       = this.BackColor;
            Color darkColor       = ControlPaint.Dark(this.BackColor);
            Color darkDarkColor   = ControlPaint.DarkDark(this.BackColor);
            Color lightlightColor = ControlPaint.LightLight(this.BackColor);

            // Office2003 style might need to perform its own drawing
            if ((Style == VisualStyle.Office2003) || (Style == VisualStyle.IDE2005))
            {
                // If the background color has not be overriden
                if (BackColor == SystemColors.Control)
                {
                    backColor       = ColorDetails.BaseColor;
                    darkColor       = ColorDetails.BaseColor2;
                    darkDarkColor   = ColorDetails.OpenBorderColor;
                    lightlightColor = darkDarkColor;
                }
            }

            switch (this.Dock)
            {
            case DockStyle.Right:
                using (Pen penD = new Pen(darkColor),
                       penDD = new Pen(darkDarkColor))
                {
                    e.Graphics.DrawLine(penD, this.Width - 2, 0, this.Width - 2, this.Height);
                    e.Graphics.DrawLine(penDD, this.Width - 1, 0, this.Width - 1, this.Height);
                }
                break;

            case DockStyle.Left:
                using (Pen penLL = new Pen(lightlightColor))
                    e.Graphics.DrawLine(penLL, 1, 0, 1, this.Height);
                break;

            case DockStyle.Bottom:
                using (Pen penD = new Pen(darkColor),
                       penDD = new Pen(darkDarkColor))
                {
                    e.Graphics.DrawLine(penD, 0, this.Height - 2, this.Width, this.Height - 2);
                    e.Graphics.DrawLine(penDD, 0, this.Height - 1, this.Width, this.Height - 1);
                }
                break;

            case DockStyle.Top:
                using (Pen penLL = new Pen(lightlightColor))
                    e.Graphics.DrawLine(penLL, 0, 1, this.Width, 1);
                break;
            }
        }
コード例 #11
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaint(e);
     foreach (var c in Controls.OfType <ColorSchemePreviewControl>())
     {
         if (c.Tag != null)
         {
             using (var border = new SolidBrush(ControlPaint.DarkDark(CurrentTheme.SecondaryColor))) {
                 var rect = Rectangle.Inflate(c.Bounds, 2, 2);
                 e.Graphics.FillRectangle(border, rect);
             }
         }
     }
 }
コード例 #12
0
        /// <summary>
        /// Make the background color of the control change automatically.
        ///
        /// Not working very well for bright colors.
        /// </summary>
        /// <param name="ctrl">Control object.</param>
        public static void ControlBackColorAutoChange(Control ctrl)
        {
            Action <object, EventArgs> ControlBackColorLight = (sender, e) => {
                Control ctrls = (Control)sender;
                ctrls.BackColor = ControlPaint.LightLight(ctrls.BackColor);
            };

            Action <object, EventArgs> ControlBackColorDark = (sender, e) => {
                Control ctrls = (Control)sender;
                ctrls.BackColor = ControlPaint.DarkDark(ctrls.BackColor);
            };

            ctrl.MouseEnter += new EventHandler(ControlBackColorDark);
            ctrl.MouseLeave += new EventHandler(ControlBackColorLight);
        }
コード例 #13
0
ファイル: QueueUsageControl.cs プロジェクト: git-thinh/core
        private Bitmap GetItemsImage(Color color)
        {
            //Debug.WriteLine("GetItemsImage");

            Bitmap itemImage;

            if (!_imagesCache.ContainsKey(color))
            {
                Rectangle rc = new Rectangle(0, 0, Width, _itemHeight);
                itemImage = new Bitmap(rc.Width, rc.Height);

                /// Create button
                rc.Inflate(-3, -3);
                GraphicsPath path1 = GetPath(rc, 10);
                rc.Inflate(0, 6);
                LinearGradientBrush br1 = new LinearGradientBrush(rc, color, Color.White, LinearGradientMode.Vertical);
                rc.Inflate(0, -6);

                /// Create shadow
                Rectangle rc2 = rc;
                rc2.Offset(8, 8);
                GraphicsPath      path2 = GetPath(rc2, 20);
                PathGradientBrush br2   = new PathGradientBrush(path2);
                br2.CenterColor    = ControlPaint.DarkDark(Color.Silver);
                br2.SurroundColors = new Color[] { Color.White };

                /// Create bubble
                Rectangle rc3 = rc;
                rc3.Inflate(-15, -rc.Height / 3);
                rc3.Y = rc3.Y - 2;
                //rc3.Height = rc3.Height;
                GraphicsPath        path3 = GetPath(rc3, rc3.Height);
                LinearGradientBrush br3   = new LinearGradientBrush(rc3, Color.FromArgb(255, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical);

                itemImage = new Bitmap(Width - 2, _itemHeight);
                Graphics g = Graphics.FromImage(itemImage);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.FillPath(br2, path2);
                g.FillPath(br1, path1);
                g.FillPath(br3, path3);

                _imagesCache[color] = itemImage;
            }

            itemImage = _imagesCache[color];

            return(itemImage);
        }
コード例 #14
0
ファイル: ResizeBar.cs プロジェクト: jugstalt/gViewGisOS
        protected override void OnPaint(PaintEventArgs e)
        {
            // Plain style draws a 3D effect around edges
            if (_style == VisualStyle.Plain)
            {
                // Drawing is relative to client area
                Size ourSize = this.ClientSize;

                Point[] light = new Point[2];
                Point[] dark  = new Point[2];
                Point[] black = new Point[2];

                // Painting depends on orientation
                if (_direction == Direction.Vertical)
                {
                    // Draw as a horizontal bar
                    dark[0].Y  = dark[1].Y = ourSize.Height - 2;
                    black[0].Y = black[1].Y = ourSize.Height - 1;
                    light[1].X = dark[1].X = black[1].X = ourSize.Width;
                }
                else
                {
                    // Draw as a vertical bar
                    dark[0].X  = dark[1].X = ourSize.Width - 2;
                    black[0].X = black[1].X = ourSize.Width - 1;
                    light[1].Y = dark[1].Y = black[1].Y = ourSize.Height;
                }

                using (Pen penLightLight = new Pen(ControlPaint.LightLight(_resizeSource.BackgroundColor)),
                       penDark = new Pen(ControlPaint.Dark(_resizeSource.BackgroundColor)),
                       penBlack = new Pen(ControlPaint.DarkDark(_resizeSource.BackgroundColor)))
                {
                    e.Graphics.DrawLine(penLightLight, light[0], light[1]);
                    e.Graphics.DrawLine(penDark, dark[0], dark[1]);
                    e.Graphics.DrawLine(penBlack, black[0], black[1]);
                }
            }

            // Let delegates fire through base
            base.OnPaint(e);
        }
コード例 #15
0
ファイル: GroupPanel.cs プロジェクト: rajeshwarn/Creek
        /// <summary>
        /// Defines the control's colors base on the parameter color
        /// </summary>
        /// <param name="newColor">Base color</param>
        protected void DefineBackColor(Color newColor)
        {
            base.BackColor = newColor;

            // Calculate the modified colors from this base
            _backColor      = newColor;
            _backLight      = ControlPaint.Light(newColor);
            _backLightLight = ControlPaint.LightLight(newColor);
            _backDark       = ControlPaint.Dark(newColor);
            _backDarkDark   = ControlPaint.DarkDark(newColor);
            // Check for the 'Classic' control color
            if ((BackColor.R == 212) &&
                (BackColor.G == 208) &&
                (BackColor.B == 200))
            {
                // Use the exact background for this color
                _backIDE = Color.FromArgb(247, 243, 233);
            }
            else
            {
                // Check for the 'XP' control color
                if ((BackColor.R == 236) &&
                    (BackColor.G == 233) &&
                    (BackColor.B == 216))
                {
                    // Use the exact background for this color
                    _backIDE = Color.FromArgb(255, 251, 233);
                }
                else
                {
                    // Calculate the IDE background color as only half as dark as the control color
                    int red   = 255 - ((255 - newColor.R) / 2);
                    int green = 255 - ((255 - newColor.G) / 2);
                    int blue  = 255 - ((255 - newColor.B) / 2);
                    _backIDE = Color.FromArgb(red, green, blue);
                }
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: Craigthomaskey/Clock
 private void darkToolStripMenuItem_Click(object sender, EventArgs e)
 {
     BackColor = Properties.Settings.Default.BackColor = SystemColors.ControlDarkDark; ForeColor = Properties.Settings.Default.TextColor = SystemColors.ButtonHighlight; Properties.Settings.Default.HighlightColor = ControlPaint.DarkDark(SystemColors.ControlDarkDark);
 }
            internal ColorData Calculate()
            {
                ColorData colors = new ColorData(this)
                {
                    ButtonFace = _backColor
                };

                if (_backColor == SystemColors.Control)
                {
                    colors.ButtonShadow     = SystemColors.ControlDark;
                    colors.ButtonShadowDark = SystemColors.ControlDarkDark;
                    colors.Highlight        = SystemColors.ControlLightLight;
                }
                else
                {
                    if (!HighContrast)
                    {
                        colors.ButtonShadow     = ControlPaint.Dark(_backColor);
                        colors.ButtonShadowDark = ControlPaint.DarkDark(_backColor);
                        colors.Highlight        = ControlPaint.LightLight(_backColor);
                    }
                    else
                    {
                        colors.ButtonShadow     = ControlPaint.Dark(_backColor);
                        colors.ButtonShadowDark = ControlPaint.LightLight(_backColor);
                        colors.Highlight        = ControlPaint.LightLight(_backColor);
                    }
                }

                colors.WindowDisabled = HighContrast ? SystemColors.GrayText : colors.ButtonShadow;

                const float lowlight = .1f;
                float       adjust   = 1 - lowlight;

                if (colors.ButtonFace.GetBrightness() < .5)
                {
                    adjust = 1 + lowlight * 2;
                }

                colors.LowButtonFace = Color.FromArgb(
                    Adjust255(adjust, colors.ButtonFace.R),
                    Adjust255(adjust, colors.ButtonFace.G),
                    Adjust255(adjust, colors.ButtonFace.B));

                adjust = 1 - lowlight;
                if (colors.Highlight.GetBrightness() < .5)
                {
                    adjust = 1 + lowlight * 2;
                }

                colors.LowHighlight = Color.FromArgb(
                    Adjust255(adjust, colors.Highlight.R),
                    Adjust255(adjust, colors.Highlight.G),
                    Adjust255(adjust, colors.Highlight.B));

                if (HighContrast && _backColor != SystemColors.Control)
                {
                    colors.Highlight = colors.LowHighlight;
                }

                colors.WindowFrame = _foreColor;

                if (colors.ButtonFace.GetBrightness() < .5)
                {
                    colors.ConstrastButtonShadow = colors.LowHighlight;
                }
                else
                {
                    colors.ConstrastButtonShadow = colors.ButtonShadow;
                }

                if (!Enabled)
                {
                    colors.WindowText = colors.WindowDisabled;
                    if (HighContrast)
                    {
                        colors.WindowFrame  = colors.WindowDisabled;
                        colors.ButtonShadow = colors.WindowDisabled;
                    }
                }
                else
                {
                    colors.WindowText = colors.WindowFrame;
                }

                using var hdc = new DeviceContextHdcScope(_deviceContext, applyGraphicsState: false);

                colors.ButtonFace            = hdc.FindNearestColor(colors.ButtonFace);
                colors.ButtonShadow          = hdc.FindNearestColor(colors.ButtonShadow);
                colors.ButtonShadowDark      = hdc.FindNearestColor(colors.ButtonShadowDark);
                colors.ConstrastButtonShadow = hdc.FindNearestColor(colors.ConstrastButtonShadow);
                colors.WindowText            = hdc.FindNearestColor(colors.WindowText);
                colors.Highlight             = hdc.FindNearestColor(colors.Highlight);
                colors.LowHighlight          = hdc.FindNearestColor(colors.LowHighlight);
                colors.LowButtonFace         = hdc.FindNearestColor(colors.LowButtonFace);
                colors.WindowFrame           = hdc.FindNearestColor(colors.WindowFrame);
                colors.WindowDisabled        = hdc.FindNearestColor(colors.WindowDisabled);

                return(colors);
            }
コード例 #18
0
 // Token: 0x06002DE4 RID: 11748 RVA: 0x00016150 File Offset: 0x00014350
 private void method_0()
 {
     this.DarkColor     = ControlPaint.Dark(this.color_0);
     this.DarkDarkColor = ControlPaint.DarkDark(this.color_0);
 }
コード例 #19
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            //g.Clear(Parent.BackColor);
            //Color clr = BackColor;

            switch (mouseAction)
            {
            case MouseActionType.Click:
                shadowOffset = 4;
                //clr = Color.Gold;
                btnOffset = 2;
                break;

            case MouseActionType.Hover:
                //clr = Color.Gold;
                break;
            }
            g.SmoothingMode = SmoothingMode.HighQuality;

            ///
            /// Create main colored shape
            ///
            Rectangle           rc    = new Rectangle(btnOffset, btnOffset, this.ClientSize.Width - 8 - btnOffset, this.ClientSize.Height - 8 - btnOffset);
            GraphicsPath        path1 = this.GetPath(rc, 20);
            LinearGradientBrush br1   = new LinearGradientBrush(new Point(0, 0), new Point(0, rc.Height + 6), color1, color2);

            ///
            /// Create shadow
            ///
            if (addShadow == true)
            {
                Rectangle rc2 = rc;
                rc2.Offset(shadowOffset, shadowOffset);
                GraphicsPath      path2 = this.GetPath(rc2, 20);
                PathGradientBrush br2   = new PathGradientBrush(path2);
                br2.CenterColor    = ControlPaint.DarkDark(Color.Silver);
                br2.SurroundColors = new Color[] { Color.Transparent };

                g.FillPath(br2, path2); //draw shadow

                ///
                ///Set the region for the button
                Region rgn = new Region(path1);
                rgn.Union(path2);
                this.Region = rgn;
            }


            ///
            /// Create top water color to give "aqua" effect
            ///
            Rectangle rc3 = rc;

            rc3.Inflate(-5, -5);
            rc3.Height = 15;
            GraphicsPath        path3 = GetPath(rc3, 20);
            LinearGradientBrush br3   = new LinearGradientBrush(rc3, Color.FromArgb(255, gradientColor), Color.FromArgb(0, gradientColor), gradientMode);

            ///
            ///draw shapes
            ///

            g.FillPath(br1, path1); //draw main
            g.FillPath(br3, path3); //draw top bubble

            ///
            ///Create a backup of the button image to a bitmap so we can manipulate it's pulsing action
            ///
            buttonBitmapRectangle = new Rectangle(rc.Location, rc.Size);
            buttonBitmap          = new Bitmap(buttonBitmapRectangle.Width, buttonBitmapRectangle.Height);
            Graphics g_bmp = Graphics.FromImage(buttonBitmap);

            g_bmp.SmoothingMode = SmoothingMode.HighQuality;
            g_bmp.FillPath(br1, path1);
            g_bmp.FillPath(br3, path3);



            ///
            /// Create a Path to draw the text to give the button a nice outline
            ///
            GraphicsPath path4 = new GraphicsPath();

            RectangleF path1bounds = path1.GetBounds();
            Rectangle  rcText      = new Rectangle((int)path1bounds.X, (int)path1bounds.Y, (int)path1bounds.Width, (int)path1bounds.Height);

            StringFormat strformat = new StringFormat();

            strformat.Alignment     = StringAlignment.Center;
            strformat.LineAlignment = StringAlignment.Center;
            path4.AddString(this.Text, this.Font.FontFamily, (int)this.Font.Style, this.Font.Size,
                            rcText, strformat);

            Pen txtPen = new Pen(this.ForeColor, 1);

            g.DrawPath(txtPen, path4);
            g_bmp.DrawPath(txtPen, path4);
        }
コード例 #20
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //
            // Calculate matching colors
            //
            Color darkColor = ForeColor;
            Color bgColor   = BackColor;

            //
            // Fill background
            //
            SolidBrush bgBrush = new SolidBrush(bgColor);

            e.Graphics.FillRectangle(bgBrush, ClientRectangle);
            bgBrush.Dispose();

            //
            // Check for value
            //
            if (_maximum == _minimum || _value == 0)
            {
                // Draw border only and exit;
                DrawBorder(e.Graphics);
                return;
            }

            //
            // The following is the width of the bar. This will vary with each value.
            //
            int fillWidth = (Width * _value) / (_maximum - _minimum);

            //
            // GDI+ doesn't like rectangles 0px wide or high
            //
            if (fillWidth == 0)
            {
                // Draw border only and exti;
                DrawBorder(e.Graphics);
                return;
            }

            //
            // Rectangles for upper and lower half of bar
            //
            Rectangle leftRect = new Rectangle(0, 0, fillWidth, Height);

            //
            // The gradient brush
            //

            //
            // Paint upper half
            //
            //brush = new LinearGradientBrush(new Point(0, 0),
            //    new Point(0, this.Height / 2), darkColor, _BarColor);
            //e.Graphics.FillRectangle(brush, topRect);
            //brush.Dispose();

            var brush = new LinearGradientBrush(new Point(0, 0),
                                                new Point(Width, Height), darkColor, _barColor);

            e.Graphics.FillRectangle(brush, leftRect);
            brush.Dispose();

            //
            // Paint lower half
            // (this.Height/2 - 1 because there would be a dark line in the middle of the bar)
            //
            //brush = new LinearGradientBrush(new Point(0, this.Height / 2 - 1),
            //    new Point(0, this.Height), _BarColor, darkColor);
            //e.Graphics.FillRectangle(brush, buttomRect);
            //brush.Dispose();

            //brush = new LinearGradientBrush(new Point(fillWidth/2, 0),
            //    new Point(fillWidth, this.Height), _BarColor, darkColor);
            //e.Graphics.FillRectangle(brush, rightRect);
            //brush.Dispose();

            //
            // Calculate separator's setting
            //
            int   sepWidth = (int)(Height * .67);
            int   sepCount = fillWidth / sepWidth;
            Color sepColor = ControlPaint.DarkDark(_barColor);

            //
            // Paint separators
            //
            switch (_fillStyle)
            {
            case FillStyles.Dashed:
                // Draw each separator line
                for (int i = 1; i <= sepCount; i++)
                {
                    e.Graphics.DrawLine(new Pen(sepColor, 1),
                                        sepWidth * i, 0, sepWidth * i, Height);
                }
                break;

            case FillStyles.Solid:
                // Draw nothing
                break;
            }

            //
            // Draw border and exit
            //
            DrawBorder(e.Graphics);
        }
コード例 #21
0
 public static Color GetSystemDarkDarkColor(Color clr)
 {
     return(ControlPaint.DarkDark(clr));
 }
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);

        RectangleF rect  = new RectangleF(new PointF(1f, 1f), new SizeF(Width - 2, Height - 2));
        RectangleF rect2 = new RectangleF(new PointF(4f, 4f), new SizeF(Width - 8, Height - 8));
        RectangleF rect3 = new RectangleF(new PointF(Width / 2f - Height * 0.3f / 7f, Height * 3.1f / 7f), new SizeF(Height * 0.8f / 7f, Height * 0.8f / 7f));

        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
        e.Graphics.FillEllipse(new SolidBrush(ControlPaint.Light(m_circleColor)), rect);
        e.Graphics.FillEllipse(new SolidBrush(m_circleColor), rect2);

        if (m_zeroLineShow)
        {
            switch (RPI_ZeroLinePosition)
            {
            case Zero.N:
                e.Graphics.DrawLine(new Pen(m_zeroLineColor), new Point(Width / 2, 1), new Point(Width / 2, Height / 2));
                break;

            case Zero.E:
                e.Graphics.DrawLine(new Pen(m_zeroLineColor), new Point((int)(Width - 2f), Height / 2), new Point(Width / 2, Height / 2));
                break;

            case Zero.W:
                e.Graphics.DrawLine(new Pen(m_zeroLineColor), new Point(2, Width / 2), new Point(Width / 2, Height / 2));
                break;

            default:                     //Zero.S
                e.Graphics.DrawLine(new Pen(m_zeroLineColor), new Point(Width / 2, (int)(Height - 2f)), new Point(Width / 2, Height / 2));
                break;
            }
        }

        e.Graphics.TranslateTransform(ClientRectangle.Width / 2f, ClientRectangle.Height / 2f);
        e.Graphics.RotateTransform(-(Convert.ToSingle(m_Value) + Convert.ToSingle(m_zeroPosition)));
        e.Graphics.TranslateTransform(-ClientRectangle.Width / 2f, -ClientRectangle.Height / 2f);

        PointF[] points = new PointF[] {
            new PointF(Width / 2f, Height * 3.1f / 7f),
            new PointF(Width * 5.25f / 7f, Height * 3.1f / 7f),
            new PointF(Width * 5.25f / 7f, Height * 6f / 16f),
            new PointF(Width - 4f, Height * 3.5f / 7f),
            new PointF(Width * 5.25f / 7f, Height * 10f / 16f),
            new PointF(Width * 5.25f / 7f, Height * 3.9f / 7f),
            new PointF(Width / 2f, Height * 3.9f / 7f)
        };

        GraphicsPath gp = new GraphicsPath();

        gp.AddPolygon(points);

        Blend lgBlend = new Blend(11)
        {
            Positions = new float[] { 0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f, 0.9f, 1f },
            Factors   = new float[] { 0f, 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.4f, 0.3f, 0.2f, 0.1f, 0f }
        };

        using (LinearGradientBrush lgBrush = new LinearGradientBrush(new Point(Width / 2, Height / 3), new Point(Width / 2, 2 * Height / 3), m_arrowColor, ControlPaint.Dark(m_arrowColor)))
        {
            lgBrush.Blend = lgBlend;
            e.Graphics.FillEllipse(lgBrush, rect3);
            e.Graphics.FillPolygon(lgBrush, points);
        }

        e.Graphics.ResetTransform();

        StringFormat sf = new StringFormat {
            Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
        };

        e.Graphics.DrawString(m_string, Font, new SolidBrush(ForeColor), new Point(Width / 2, Height * 2 / 3), sf);

        if (!string.IsNullOrEmpty(Text))
        {
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(Width / 2, Height / 2), sf);
        }
        else
        {
            e.Graphics.FillEllipse(new SolidBrush(ControlPaint.DarkDark(m_circleColor)), Convert.ToSingle(Width / 2 - 1f), Convert.ToSingle(Height / 2 - 1f), 2f, 2f);
        }
    }