예제 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            base.OnPaintBackground(e);
            Graphics  g = e.Graphics;
            Rectangle checkButtonRect;
            Rectangle textRect;

            CalculateRect(out checkButtonRect, out textRect);
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Color backColor = ControlPaint.Light(_baseColor);

            if (Enabled || true)
            {
                switch (ControlState)
                {
                case ControlState.Hover:
                    image = Checked ? ESkin.Properties.Resources._16x16勾选点击状态 : ESkin.Properties.Resources._16x16_没勾选点击状态;
                    break;

                case ControlState.Pressed:
                    image = Checked ? ESkin.Properties.Resources._16x16勾选点击状态 : ESkin.Properties.Resources._16x16_没勾选点击状态;
                    break;

                default:
                    image = Checked ? ESkin.Properties.Resources._16x16勾选 : ESkin.Properties.Resources._16x16_没勾选;
                    break;
                }
            }
            DrawCheckedFlag(g, checkButtonRect, image);
            Color textColor = Enabled ? ForeColor : SystemColors.GrayText;

            TextRenderer.DrawText(
                g,
                Text,
                Font,
                textRect,
                textColor,
                GetTextFormatFlags(TextAlign, RightToLeft == RightToLeft.Yes));
        }
예제 #2
0
파일: Theme.cs 프로젝트: yonder/mono
        public CPColor GetCPColor(Color color)
        {
            lock (cpcolors) {
                object tmp = cpcolors [color];

                if (tmp == null)
                {
                    CPColor cpcolor = new CPColor();
                    cpcolor.Dark       = ControlPaint.Dark(color);
                    cpcolor.DarkDark   = ControlPaint.DarkDark(color);
                    cpcolor.Light      = ControlPaint.Light(color);
                    cpcolor.LightLight = ControlPaint.LightLight(color);

                    cpcolors.Add(color, cpcolor);

                    return(cpcolor);
                }

                return((CPColor)tmp);
            }
        }
예제 #3
0
        private static void DrawUnthemedGroupBoxNoText(Graphics g, Rectangle bounds)
        {
            Color backColor = SystemColors.Control;

            using var light = ControlPaint.Light(backColor, 1.0f).GetCachedPenScope();
            using var dark  = ControlPaint.Dark(backColor, 0f).GetCachedPenScope();

            // left
            g.DrawLine(light, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Height - 1);
            g.DrawLine(dark, bounds.Left, bounds.Top + 1, bounds.Left, bounds.Height - 2);

            // bottom
            g.DrawLine(light, bounds.Left, bounds.Height - 1, bounds.Width - 1, bounds.Height - 1);
            g.DrawLine(dark, bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2);

            // top
            g.DrawLine(light, bounds.Left + 1, bounds.Top + 1, bounds.Width - 1, bounds.Top + 1);
            g.DrawLine(dark, bounds.Left, bounds.Top, bounds.Width - 2, bounds.Top);

            // right
            g.DrawLine(light, bounds.Width - 1, bounds.Top, bounds.Width - 1, bounds.Height - 1);
            g.DrawLine(dark, bounds.Width - 2, bounds.Top, bounds.Width - 2, bounds.Height - 2);
        }
예제 #4
0
        /// <summary>
        ///     Draws an un-themed GroupBox with no text label.
        /// </summary>
        private static void DrawUnthemedGroupBoxNoText(Graphics g, Rectangle bounds, GroupBoxState state)
        {
            Color backColor = SystemColors.Control;
            Pen   light     = new Pen(ControlPaint.Light(backColor, 1.0f));
            Pen   dark      = new Pen(ControlPaint.Dark(backColor, 0f));

            try
            {
                // left
                g.DrawLine(light, bounds.Left + 1, bounds.Top + 1, bounds.Left + 1, bounds.Height - 1);
                g.DrawLine(dark, bounds.Left, bounds.Top + 1, bounds.Left, bounds.Height - 2);

                // bottom
                g.DrawLine(light, bounds.Left, bounds.Height - 1, bounds.Width - 1, bounds.Height - 1);
                g.DrawLine(dark, bounds.Left, bounds.Height - 2, bounds.Width - 1, bounds.Height - 2);

                // top
                g.DrawLine(light, bounds.Left + 1, bounds.Top + 1, bounds.Width - 1, bounds.Top + 1);
                g.DrawLine(dark, bounds.Left, bounds.Top, bounds.Width - 2, bounds.Top);

                // right
                g.DrawLine(light, bounds.Width - 1, bounds.Top, bounds.Width - 1, bounds.Height - 1);
                g.DrawLine(dark, bounds.Width - 2, bounds.Top, bounds.Width - 2, bounds.Height - 2);
            }
            finally
            {
                if (light != null)
                {
                    light.Dispose();
                }
                if (dark != null)
                {
                    dark.Dispose();
                }
            }
        }
        static X11DesktopColors()
        {
            FindDesktopEnvironment();

            switch (desktop)
            {
            case Desktop.Gtk:
            {
                //IntPtr		dispmgr;
                //IntPtr		gdkdisplay;
                IntPtr         widget;
                IntPtr         style_ptr;
                GtkStyleStruct style;

                try
                {
                    GtkInit();
                    //dispmgr =  gdk_display_manager_get ();
                    //gdkdisplay =  gdk_display_manager_get_default_display (dispmgr);

                    widget = gtk_invisible_new();
                    gtk_widget_ensure_style(widget);
                    style_ptr = gtk_widget_get_style(widget);

                    style = (GtkStyleStruct)Marshal.PtrToStructure(style_ptr, typeof(GtkStyleStruct));

                    ThemeEngine.Current.ColorControl           = ColorFromGdkColor(style.bg[0]);
                    ThemeEngine.Current.ColorControlText       = ColorFromGdkColor(style.fg[0]);
                    ThemeEngine.Current.ColorControlDark       = ColorFromGdkColor(style.dark[0]);
                    ThemeEngine.Current.ColorControlLight      = ColorFromGdkColor(style.light[0]);
                    ThemeEngine.Current.ColorControlLightLight = ControlPaint.Light(ColorFromGdkColor(style.light[0]));
                    ThemeEngine.Current.ColorControlDarkDark   = ControlPaint.Dark(ColorFromGdkColor(style.dark[0]));

                    widget = gtk_menu_new();
                    gtk_widget_ensure_style(widget);
                    style_ptr = gtk_widget_get_style(widget);

                    style = (GtkStyleStruct)Marshal.PtrToStructure(style_ptr, typeof(GtkStyleStruct));

                    ThemeEngine.Current.ColorMenu     = ColorFromGdkColor(style.bg [0]);
                    ThemeEngine.Current.ColorMenuText = ColorFromGdkColor(style.text [0]);
                }

                catch (DllNotFoundException)
                {
                    Console.Error.WriteLine("Gtk not found (missing LD_LIBRARY_PATH to libgtk-x11-2.0.so.0?), using built-in colorscheme");
                }

                catch
                {
                    Console.Error.WriteLine("Gtk colorscheme read failure, using built-in colorscheme");
                }
                break;
            }

            case Desktop.KDE:
            {
                if (!ReadKDEColorsheme())
                {
                    Console.Error.WriteLine("KDE colorscheme read failure, using built-in colorscheme");
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
        private void DrawGroupBox(PaintEventArgs e)
        {
            Graphics  graphics        = e.Graphics;
            Rectangle clientRectangle = base.ClientRectangle;
            int       num             = 8;
            Color     disabledColor   = base.DisabledColor;
            Pen       pen             = new Pen(ControlPaint.Light(disabledColor, 1f));
            Pen       pen2            = new Pen(ControlPaint.Dark(disabledColor, 0f));

            clientRectangle.X     += num;
            clientRectangle.Width -= 2 * num;
            try
            {
                Size size;
                int  num2;
                if (this.UseCompatibleTextRendering)
                {
                    using (Brush brush = new SolidBrush(this.ForeColor))
                    {
                        using (StringFormat format = new StringFormat())
                        {
                            format.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
                            if (this.RightToLeft == RightToLeft.Yes)
                            {
                                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                            }
                            size = Size.Ceiling(graphics.MeasureString(this.Text, this.Font, clientRectangle.Width, format));
                            if (base.Enabled)
                            {
                                graphics.DrawString(this.Text, this.Font, brush, clientRectangle, format);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(graphics, this.Text, this.Font, disabledColor, clientRectangle, format);
                            }
                        }
                        goto Label_01E7;
                    }
                }
                using (WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(graphics))
                {
                    IntTextFormatFlags flags = IntTextFormatFlags.TextBoxControl | IntTextFormatFlags.WordBreak;
                    if (!this.ShowKeyboardCues)
                    {
                        flags |= IntTextFormatFlags.HidePrefix;
                    }
                    if (this.RightToLeft == RightToLeft.Yes)
                    {
                        flags |= IntTextFormatFlags.RightToLeft;
                        flags |= IntTextFormatFlags.Right;
                    }
                    using (WindowsFont font = WindowsGraphicsCacheManager.GetWindowsFont(this.Font))
                    {
                        size = graphics2.MeasureText(this.Text, font, new Size(clientRectangle.Width, 0x7fffffff), flags);
                        if (base.Enabled)
                        {
                            graphics2.DrawText(this.Text, font, clientRectangle, this.ForeColor, flags);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(graphics2, this.Text, this.Font, disabledColor, clientRectangle, (TextFormatFlags)flags);
                        }
                    }
                }
Label_01E7:
                num2 = num;
                if (this.RightToLeft == RightToLeft.Yes)
                {
                    num2 += clientRectangle.Width - size.Width;
                }
                int num3 = Math.Min((int)(num2 + size.Width), (int)(base.Width - 6));
                int num4 = base.FontHeight / 2;
                graphics.DrawLine(pen, 1, num4, 1, base.Height - 1);
                graphics.DrawLine(pen2, 0, num4, 0, base.Height - 2);
                graphics.DrawLine(pen, 0, base.Height - 1, base.Width, base.Height - 1);
                graphics.DrawLine(pen2, 0, base.Height - 2, base.Width - 1, base.Height - 2);
                graphics.DrawLine(pen2, 0, num4 - 1, num2, num4 - 1);
                graphics.DrawLine(pen, 1, num4, num2, num4);
                graphics.DrawLine(pen2, num3, num4 - 1, base.Width - 2, num4 - 1);
                graphics.DrawLine(pen, num3, num4, base.Width - 1, num4);
                graphics.DrawLine(pen, (int)(base.Width - 1), (int)(num4 - 1), (int)(base.Width - 1), (int)(base.Height - 1));
                graphics.DrawLine(pen2, base.Width - 2, num4, base.Width - 2, base.Height - 2);
            }
            finally
            {
                pen.Dispose();
                pen2.Dispose();
            }
        }
예제 #7
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();
            }
        }
예제 #8
0
        /// <include file='doc\GroupBox.uex' path='docs/doc[@for="GroupBox.OnPaint"]/*' />
        /// <internalonly/>
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics  graphics      = e.Graphics;
            Rectangle textRectangle = ClientRectangle;

            int textOffset = 8;

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

            Brush        textBrush = new SolidBrush(ForeColor);
            StringFormat format    = new StringFormat();

            if (ShowKeyboardCues)
            {
                format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
            }
            else
            {
                format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
            }

            // Adjust string format for Rtl controls
            if (RightToLeft == RightToLeft.Yes)
            {
                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

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

            Color backColor = DisabledColor;

            if (Enabled)
            {
                graphics.DrawString(Text, Font, textBrush, textRectangle, format);
            }
            else
            {
                ControlPaint.DrawStringDisabled(graphics, Text, Font, backColor, textRectangle, format);
            }

            format.Dispose();
            textBrush.Dispose();

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

            int textLeft = textOffset;

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

            int boxTop = FontHeight / 2;

            // 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, textLeft + textSize.Width, boxTop - 1, Width - 2, boxTop - 1);
            graphics.DrawLine(light, textLeft + textSize.Width, 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);

            // light.Dispose();
            // dark.Dispose();

            base.OnPaint(e); // raise paint event
        }