Beispiel #1
0
        public override void DrawCommentsBackground(Graphics graphics, Rectangle commentRect)
        {
            using (Brush brush = new SolidBrush(Grid.CommentsBackColor))
                graphics.FillRectangle(brush, commentRect);

            commentRect.Width--;
            commentRect.Height--;
            graphics.DrawRectangle(SystemPens.FromSystemColor(SystemColors.GrayText), commentRect);
        }
 private static bool GetPen(Color color, ref Pen pen)
 {
     if (color.IsSystemColor)
     {
         pen = SystemPens.FromSystemColor(color);
         return(false);
     }
     pen = new Pen(color);
     return(true);
 }
Beispiel #3
0
        private void RenderRadio(Context ctx, State.Radio stateid, Rectangle prect)
        {
            Brush backBrush;
            Color foreColor;

            switch (stateid)
            {
            case State.Radio.RBS_UNCHECKEDNORMAL:
            case State.Radio.RBS_CHECKEDNORMAL:
                backBrush = SystemBrushes.Window;
                foreColor = SystemColors.WindowText;
                break;

            case State.Radio.RBS_UNCHECKEDHOT:
            case State.Radio.RBS_CHECKEDHOT:
                backBrush = SystemBrushes.Window;
                foreColor = SystemColors.HotTrack;
                break;

            case State.Radio.RBS_UNCHECKEDPRESSED:
            case State.Radio.RBS_CHECKEDPRESSED:
                backBrush = SystemBrushes.ControlLightLight;
                foreColor = SystemColors.HotTrack;
                break;

            // case State.Radio.RBS_UNCHECKEDDISABLED:
            // case State.Radio.RBS_CHECKEDDISABLED:
            default:
                backBrush = SystemBrushes.ControlLight;
                foreColor = SystemColors.ControlDark;
                break;
            }

            using (ctx.HighQuality())
            {
                var rect = prect.Inclusive();
                ctx.Graphics.FillEllipse(backBrush, rect);
                ctx.Graphics.DrawEllipse(SystemPens.FromSystemColor(foreColor), rect);
                var padding = DpiUtil.Scale(new Size(-3, -3));
                switch (stateid)
                {
                case State.Radio.RBS_CHECKEDNORMAL:
                case State.Radio.RBS_CHECKEDHOT:
                case State.Radio.RBS_CHECKEDPRESSED:
                case State.Radio.RBS_CHECKEDDISABLED:
                    rect.Inflate(padding);
                    ctx.Graphics.FillEllipse(SystemBrushes.FromSystemColor(foreColor), rect);
                    break;
                }
            }
        }
Beispiel #4
0
        public void TestFromSystemColor()
        {
            Pen pen;

            pen = SystemPens.FromSystemColor(SystemColors.MenuText);
            CheckProperties(pen, "P16", SystemColors.MenuText);
            CheckMethods(pen, "M16");

            try {
                pen = SystemPens.FromSystemColor(Color.Red);
                Assert.Fail("M17: must throw ArgumentException");
            } catch (ArgumentException) {
                Assert.IsTrue(true, "M17");
            }
        }
Beispiel #5
0
        public override void DrawButtonsGap(Graphics graphics, Rectangle rect)
        {
            Pen whitePen = new Pen(Color.White);

            graphics.DrawLine(whitePen, rect.Left, rect.Bottom - 3, rect.Right, rect.Bottom - 3);
            whitePen.Dispose();

            Pen lightPen = SystemPens.FromSystemColor(SystemColors.ControlLight);

            graphics.DrawLine(lightPen, rect.Left, rect.Bottom - 2, rect.Right, rect.Bottom - 2);

            Pen darkPen = SystemPens.FromSystemColor(SystemColors.ControlDark);

            graphics.DrawLine(darkPen, rect.Left, rect.Bottom - 1, rect.Right, rect.Bottom - 1);
        }
Beispiel #6
0
        protected override void RenderNodeOutline(Graphics graphics, KTreeNode node, Rectangle rect, KTreeNodeMeasurements.Part?highlight)
        {
            if (highlight != null)
            {
                graphics.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.HotTrack), rect);
            }
            else if (node.IsSelected)
            {
                graphics.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.Highlight), rect);
            }

            if (_tree.ActiveNode == node && !node.IsSelected)
            {
                graphics.DrawRectangle(SystemPens.FromSystemColor(SystemColors.HotTrack), rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
            }
        }
Beispiel #7
0
        private static PenCache.Scope GetPenScope(Color color)
        {
            if (color.IsKnownColor)
            {
                Pen?pen = color.IsSystemColor
                    ? SystemPens.FromSystemColor(color)
                    : PenFromKnownColor(color.ToKnownColor());

                if (pen is not null)
                {
                    return(new PenCache.Scope(pen));
                }
            }

            return(PenCache.GetEntry(color));
        }
Beispiel #8
0
        public override void DrawCommentsGap(Graphics graphics, Rectangle rect)
        {
            Pen whitePen = new Pen(Color.White);

            graphics.DrawLine(whitePen, rect.Left, rect.Top, rect.Right, rect.Top);
            graphics.DrawLine(whitePen, rect.Left, rect.Top + 2, rect.Right, rect.Top + 2);
            whitePen.Dispose();

            Pen lightPen = SystemPens.FromSystemColor(SystemColors.ControlLight);

            graphics.DrawLine(lightPen, rect.Left, rect.Top + 1, rect.Right, rect.Top + 1);
            graphics.DrawLine(lightPen, rect.Left, rect.Top + 3, rect.Right, rect.Top + 3);

            Pen darkPen = SystemPens.FromSystemColor(SystemColors.ControlDark);

            graphics.DrawLine(darkPen, rect.Left, rect.Top + 4, rect.Right, rect.Top + 4);

            Pen darkDarkPen = SystemPens.FromSystemColor(SystemColors.ControlDarkDark);

            graphics.DrawLine(darkDarkPen, rect.Left, rect.Top + 5, rect.Right, rect.Top + 5);
        }
Beispiel #9
0
        private void Form1_Paint(object sender,
                                 System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            // Create a pen using SystemPens
            Pen pn = SystemPens.FromSystemColor(
                SystemColors.HotTrack);
            // Create a brush using SystemBrushes
            SolidBrush brush =
                (SolidBrush)SystemBrushes.FromSystemColor
                    (SystemColors.ActiveCaption);

            // Draw lines and rectangles
            g.DrawLine(pn, 20, 20, 20, 100);
            g.DrawLine(pn, 20, 20, 100, 20);
            g.FillRectangle(brush, 30, 30, 50, 50);
            // YOU CAN'T DISPOSE System pens AND
            // brushes. IF YOU TRY, GDI+ WILL GENERATE
            // AN ERROR
            //pn.Dispose();
            //brush.Dispose();
        }
Beispiel #10
0
        private void SystemColorsMenu_Click(object sender,
                                            System.EventArgs e)
        {
            // Create a Graphics object
            Graphics g = this.CreateGraphics();
            // Create brushes and pens
            SolidBrush brush1 =
                (SolidBrush)SystemBrushes.FromSystemColor
                    (SystemColors.ActiveCaption);
            Pen pn1 = SystemPens.FromSystemColor
                          (SystemColors.HighlightText);
            Pen pn2 = SystemPens.FromSystemColor
                          (SystemColors.ControlLightLight);
            Pen pn3 = SystemPens.FromSystemColor
                          (SystemColors.ControlDarkDark);

            // Draw and fill graphics objects
            g.DrawLine(pn1, 10, 10, 10, 200);
            g.FillRectangle(brush1, 60, 60, 100, 100);
            g.DrawEllipse(pn3, 20, 20, 170, 170);
            g.DrawLine(pn2, 10, 10, 200, 10);
            // Dispose
            g.Dispose();
        }
Beispiel #11
0
        private void DrawGroupBox(PaintEventArgs e)
        {
            Graphics  graphics      = e.Graphics;
            Rectangle textRectangle = ClientRectangle; // Max text bounding box passed to drawing methods to support RTL.

            int textOffset = 8;                        // Offset from the left bound.

            Color backColor = DisabledColor;

            Pen  light = new Pen(ControlPaint.Light(backColor, 1.0f));
            Pen  dark  = new Pen(ControlPaint.Dark(backColor, 0f));
            Size textSize;

            textRectangle.X     += textOffset;
            textRectangle.Width -= 2 * textOffset;

            try {
                if (UseCompatibleTextRendering)
                {
                    using (Brush textBrush = new SolidBrush(ForeColor)){
                        using (StringFormat format = new StringFormat()){
                            format.HotkeyPrefix = ShowKeyboardCues ? System.Drawing.Text.HotkeyPrefix.Show : System.Drawing.Text.HotkeyPrefix.Hide;

                            // Adjust string format for Rtl controls

                            if (RightToLeft == RightToLeft.Yes)
                            {
                                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                            }

                            textSize = Size.Ceiling(graphics.MeasureString(Text, Font, textRectangle.Width, format));

                            if (Enabled)
                            {
                                graphics.DrawString(Text, Font, textBrush, textRectangle, format);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(graphics, Text, Font, backColor, textRectangle, format);
                            }
                        }
                    }
                }
                else
                {
                    using (WindowsGraphics wg = WindowsGraphics.FromGraphics(graphics)){
                        IntTextFormatFlags flags = IntTextFormatFlags.WordBreak | IntTextFormatFlags.TextBoxControl;

                        if (!ShowKeyboardCues)
                        {
                            flags |= IntTextFormatFlags.HidePrefix;
                        }

                        if (RightToLeft == RightToLeft.Yes)
                        {
                            flags |= IntTextFormatFlags.RightToLeft;
                            flags |= IntTextFormatFlags.Right;
                        }


                        using (WindowsFont wfont = WindowsGraphicsCacheManager.GetWindowsFont(this.Font)) {
                            textSize = wg.MeasureText(Text, wfont, new Size(textRectangle.Width, int.MaxValue), flags);

                            if (Enabled)
                            {
                                wg.DrawText(Text, wfont, textRectangle, ForeColor, flags);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(wg, Text, Font, backColor, textRectangle, ((TextFormatFlags)flags));
                            }
                        }
                    }
                }

                int textLeft = textOffset;    // Left side of binding box (independent on RTL).

                if (RightToLeft == RightToLeft.Yes)
                {
                    textLeft += textRectangle.Width - textSize.Width;
                }

                // Math.Min to assure we paint at least a small line.
                int textRight = Math.Min(textLeft + textSize.Width, Width - 6);

                int boxTop = FontHeight / 2;

                if (SystemInformation.HighContrast && AccessibilityImprovements.Level1)
                {
                    Color boxColor;
                    if (Enabled)
                    {
                        boxColor = ForeColor;
                    }
                    else
                    {
                        boxColor = SystemColors.GrayText;
                    }
                    bool needToDispose = !boxColor.IsSystemColor;
                    Pen  boxPen        = null;
                    try {
                        if (needToDispose)
                        {
                            boxPen = new Pen(boxColor);
                        }
                        else
                        {
                            boxPen = SystemPens.FromSystemColor(boxColor);
                        }

                        // left
                        graphics.DrawLine(boxPen, 0, boxTop, 0, Height);
                        //bottom
                        graphics.DrawLine(boxPen, 0, Height - 1, Width, Height - 1);
                        //top-left
                        graphics.DrawLine(boxPen, 0, boxTop, textLeft, boxTop);
                        //top-right
                        graphics.DrawLine(boxPen, textRight, boxTop, Width - 1, boxTop);
                        //right
                        graphics.DrawLine(boxPen, Width - 1, boxTop, Width - 1, Height - 1);
                    }
                    finally {
                        if (needToDispose && boxPen != null)
                        {
                            boxPen.Dispose();
                        }
                    }
                }
                else
                {
                    // left
                    graphics.DrawLine(light, 1, boxTop, 1, Height - 1);
                    graphics.DrawLine(dark, 0, boxTop, 0, Height - 2);

                    // bottom
                    graphics.DrawLine(light, 0, Height - 1, Width, Height - 1);
                    graphics.DrawLine(dark, 0, Height - 2, Width - 1, Height - 2);

                    // top-left

                    graphics.DrawLine(dark, 0, boxTop - 1, textLeft, boxTop - 1);
                    graphics.DrawLine(light, 1, boxTop, textLeft, boxTop);

                    // top-right
                    graphics.DrawLine(dark, textRight, boxTop - 1, Width - 2, boxTop - 1);
                    graphics.DrawLine(light, textRight, boxTop, Width - 1, boxTop);

                    // right
                    graphics.DrawLine(light, Width - 1, boxTop - 1, Width - 1, Height - 1);
                    graphics.DrawLine(dark, Width - 2, boxTop, Width - 2, Height - 2);
                }
            }
            finally {
                light.Dispose();
                dark.Dispose();
            }
        }
Beispiel #12
0
 public void FromSystemColor_NotSystemColor_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(null, () => SystemPens.FromSystemColor(Color.Blue));
 }
Beispiel #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            bool hovered = this.RectangleToScreen(this.ClientRectangle).Contains(MousePosition);

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            //content border
            Rectangle rectCont = rectContent;

            rectCont.X      += 1;
            rectCont.Y      += 1;
            rectCont.Width  -= 3;
            rectCont.Height -= 3;
            GraphicsPath pathContentBorder = CreateRoundRectangle(rectCont, Radius.TopLeft, Radius.TopRight, Radius.BottomRight,
                                                                  Radius.BottomLeft);

            //button border
            Rectangle rectButton = rectBtn;

            rectButton.X      += 1;
            rectButton.Y      += 1;
            rectButton.Width  -= 3;
            rectButton.Height -= 3;
            GraphicsPath pathBtnBorder = CreateRoundRectangle(rectButton, 0, Radius.TopRight, Radius.BottomRight, 0);

            //outer border
            Rectangle rectOuter = rectContent;

            rectOuter.Width  -= 1;
            rectOuter.Height -= 1;
            GraphicsPath pathOuterBorder = CreateRoundRectangle(rectOuter, Radius.TopLeft, Radius.TopRight, Radius.BottomRight,
                                                                Radius.BottomLeft);

            //inner border
            Rectangle rectInner = rectContent;

            rectInner.X      += 1;
            rectInner.Y      += 1;
            rectInner.Width  -= 3;
            rectInner.Height -= 3;
            GraphicsPath pathInnerBorder = CreateRoundRectangle(rectInner, Radius.TopLeft, Radius.TopRight, Radius.BottomRight,
                                                                Radius.BottomLeft);

            //brushes and pens
            Color foreColor    = Color.FromArgb(DroppedDown ? 100 : 50, ForeColor);
            Brush brInnerBrush = new LinearGradientBrush(
                new Rectangle(rectInner.X, rectInner.Y, rectInner.Width, rectInner.Height + 1),
                Color.FromArgb((hovered || DroppedDown || Focused) ? 200 : 100, ForeColor),
                Color.Transparent,
                LinearGradientMode.Vertical);
            Brush brBackground;

            if (this.DropDownStyle == ComboBoxStyle.DropDownList)
            {
                brBackground = new LinearGradientBrush(pathInnerBorder.GetBounds(), BackColor, (hovered || Focused)? Color.FromArgb(100, SystemColors.HotTrack) : foreColor, LinearGradientMode.Vertical);
            }
            else
            {
                brBackground = new SolidBrush(BackColor);
            }
            Pen penInnerBorder = new Pen(brInnerBrush, 0);
            LinearGradientBrush brButtonLeft = new LinearGradientBrush(rectBtn, BackColor, ForeColor, LinearGradientMode.Vertical);
            ColorBlend          blend        = new ColorBlend();

            blend.Colors    = new Color[] { Color.Transparent, foreColor, Color.Transparent };
            blend.Positions = new float[] { 0.0f, 0.5f, 1.0f };
            brButtonLeft.InterpolationColors = blend;
            Pen   penLeftButton = new Pen(brButtonLeft, 0);
            Brush brButton      = new LinearGradientBrush(pathBtnBorder.GetBounds(), BackColor, foreColor, LinearGradientMode.Vertical);

            //draw
            e.Graphics.FillPath(brBackground, pathContentBorder);
            if (DropDownStyle != ComboBoxStyle.DropDownList)
            {
                e.Graphics.FillPath(brButton, pathBtnBorder);
            }
            Color outerBorderColor = GetOuterBorderColor();

            if (outerBorderColor.IsSystemColor)
            {
                Pen penOuterBorder = SystemPens.FromSystemColor(outerBorderColor);
                e.Graphics.DrawPath(penOuterBorder, pathOuterBorder);
            }
            else
            {
                using (Pen penOuterBorder = new Pen(outerBorderColor))
                    e.Graphics.DrawPath(penOuterBorder, pathOuterBorder);
            }
            e.Graphics.DrawPath(penInnerBorder, pathInnerBorder);

            e.Graphics.DrawLine(penLeftButton, rectBtn.Left + 1, rectInner.Top + 1, rectBtn.Left + 1, rectInner.Bottom - 1);


            //Glimph
            Rectangle rectGlimph = rectButton;

            rectButton.Width -= 4;
            e.Graphics.TranslateTransform(rectGlimph.Left + rectGlimph.Width / 2.0f, rectGlimph.Top + rectGlimph.Height / 2.0f);
            GraphicsPath path = new GraphicsPath();

            PointF[] points = new PointF[3];
            points[0] = new PointF(-6 / 2.0f, -3 / 2.0f);
            points[1] = new PointF(6 / 2.0f, -3 / 2.0f);
            points[2] = new PointF(0, 6 / 2.0f);
            path.AddLine(points[0], points[1]);
            path.AddLine(points[1], points[2]);
            path.CloseFigure();
            e.Graphics.RotateTransform(0);

            SolidBrush br = new SolidBrush(Enabled ? Color.Gray : Color.Gainsboro);

            e.Graphics.FillPath(br, path);
            e.Graphics.ResetTransform();
            br.Dispose();
            path.Dispose();

            // image
            if (ImageList != null)
            {
                int idx = GetImageKey(SelectedIndex);
                if (idx >= 0)
                {
                    this.ImageList.Draw(e.Graphics, rectTextBounds.Left - this.ImageList.ImageSize.Width - 5, rectContent.Y + 2, idx);
                }
            }

            //text
            if (DropDownStyle == ComboBoxStyle.DropDownList)
            {
                StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
                sf.Alignment = StringAlignment.Near;

                Rectangle rectText = rectTextBounds;
                rectText.Offset(-3, 0);

                SolidBrush foreBrush = new SolidBrush(ForeColor);
                if (Enabled)
                {
                    e.Graphics.DrawString(Text, this.Font, foreBrush, rectText, sf);
                }
                else
                {
                    ControlPaint.DrawStringDisabled(e.Graphics, Text, Font, BackColor, rectText, sf);
                }
            }

            /*
             * Dim foreBrush As SolidBrush = New SolidBrush(color)
             * If (enabled) Then
             *      g.DrawString(text, font, foreBrush, rect, sf)
             * Else
             *      ControlPaint.DrawStringDisabled(g, text, font, backColor, _
             *               rect, sf)
             * End If
             * foreBrush.Dispose()*/


            pathContentBorder.Dispose();
            pathOuterBorder.Dispose();
            pathInnerBorder.Dispose();
            pathBtnBorder.Dispose();

            penInnerBorder.Dispose();
            penLeftButton.Dispose();

            brBackground.Dispose();
            brInnerBrush.Dispose();
            brButtonLeft.Dispose();
            brButton.Dispose();
        }
Beispiel #14
0
 protected Pen GetSystemPen(Color color)
 {
     return(SystemPens.FromSystemColor(color));
 }
Beispiel #15
0
 private DrawPattern(Color line, Color text, int imageIndex)
 {
     Line       = line.IsSystemColor ? SystemPens.FromSystemColor(line) : new Pen(line, 1);
     Text       = text;
     ImageIndex = imageIndex;
 }
Beispiel #16
0
 private DrawPattern(Color line, Color text, Image arrow)
 {
     Line  = line.IsSystemColor ? SystemPens.FromSystemColor(line) : new Pen(line, 1);
     Text  = text;
     Arrow = arrow;
 }