示例#1
0
        public virtual void DrawPopupPressedCheckBox(Graphics g, Rectangle_ bounds, Color_ backColor, Color_ foreColor, CheckState state)
        {
            Rectangle_ checkbox_rectangle;
            Rectangle_ fill_rectangle;

            // clip one pixel from bottom right for non popup rendered checkboxes
            checkbox_rectangle = new Rectangle_(bounds.X, bounds.Y, Math.Max(bounds.Width - 1, 0), Math.Max(bounds.Height - 1, 0));
            fill_rectangle     = new Rectangle_(checkbox_rectangle.X + 1, checkbox_rectangle.Y + 1, Math.Max(checkbox_rectangle.Width - 3, 0), Math.Max(checkbox_rectangle.Height - 3, 0));

            g.FillRectangle(ResPool.GetSolidBrush(backColor), fill_rectangle);

            // draw sunken effect
            ThemeEngine.Current.CPDrawBorder3D(g, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, backColor);

            bounds.Offset(-1, 0);

            if (state == CheckState.Checked)
            {
                DrawCheck(g, bounds, Color_.Black);
            }
            else if (state == CheckState.Indeterminate)
            {
                DrawCheck(g, bounds, SystemColors.ControlDarkDark);
            }
        }
示例#2
0
        public static void DrawTabItem(Graphics g, Rectangle_ bounds, string tabItemText, Font font, TextFormatFlags flags, Image image, Rectangle_ imageRectangle, bool focused, TabItemState state)
        {
            if (!IsSupported)
            {
                throw new InvalidOperationException();
            }

            VisualStyleRenderer vsr;

            switch (state)
            {
            case TabItemState.Disabled:
                vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Disabled);
                break;

            case TabItemState.Hot:
                vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Hot);
                break;

            case TabItemState.Normal:
            default:
                vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Normal);
                break;

            case TabItemState.Selected:
                vsr = new VisualStyleRenderer(VisualStyleElement.Tab.TabItem.Pressed);
                break;
            }

            vsr.DrawBackground(g, bounds);

            if (image != null)
            {
                vsr.DrawImage(g, imageRectangle, image);
            }

            bounds.Offset(3, 3);
            bounds.Height -= 6;
            bounds.Width  -= 6;

            if (tabItemText != String.Empty)
            {
                TextRenderer.DrawText(g, tabItemText, font, bounds, SystemColors.ControlText, flags);
            }

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, bounds);
            }
        }
示例#3
0
        public virtual void DrawFlatDisabledCheckBox(Graphics g, Rectangle_ bounds, Color_ backColor, Color_ foreColor, CheckState state)
        {
            Rectangle_ checkbox_rectangle;

            checkbox_rectangle = new Rectangle_(bounds.X, bounds.Y, Math.Max(bounds.Width - 2, 0), Math.Max(bounds.Height - 2, 0));

            ControlPaint.DrawBorder(g, checkbox_rectangle, foreColor, ButtonBorderStyle.Solid);

            bounds.Offset(-1, 0);

            if (state == CheckState.Checked || state == CheckState.Indeterminate)
            {
                DrawCheck(g, bounds, SystemColors.ControlDarkDark);
            }
        }
示例#4
0
        protected override void OnRenderGrip(ToolStripGripRenderEventArgs e)
        {
            if (e.GripStyle == ToolStripGripStyle.Hidden)
            {
                return;
            }

            if (e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical)
            {
                Rectangle_ r = new Rectangle_(e.GripBounds.Left, e.GripBounds.Top + 5, 2, 2);

                for (int i = 0; i < e.GripBounds.Height - 12; i += 4)
                {
                    e.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(this.ColorTable.GripLight), r);
                    r.Offset(0, 4);
                }

                Rectangle_ r2 = new Rectangle_(e.GripBounds.Left - 1, e.GripBounds.Top + 4, 2, 2);

                for (int i = 0; i < e.GripBounds.Height - 12; i += 4)
                {
                    e.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(this.ColorTable.GripDark), r2);
                    r2.Offset(0, 4);
                }
            }
            else
            {
                Rectangle_ r = new Rectangle_(e.GripBounds.Left + 5, e.GripBounds.Top, 2, 2);

                for (int i = 0; i < e.GripBounds.Width - 11; i += 4)
                {
                    e.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(this.ColorTable.GripLight), r);
                    r.Offset(4, 0);
                }

                Rectangle_ r2 = new Rectangle_(e.GripBounds.Left + 4, e.GripBounds.Top - 1, 2, 2);

                for (int i = 0; i < e.GripBounds.Width - 11; i += 4)
                {
                    e.Graphics.FillRectangle(ThemeEngine.Current.ResPool.GetSolidBrush(this.ColorTable.GripDark), r2);
                    r2.Offset(4, 0);
                }
            }

            base.OnRenderGrip(e);
        }
示例#5
0
        protected override void Paint(Graphics graphics, Rectangle_ clipBounds, Rectangle_ cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            // Prepaint
            DataGridViewPaintParts pre = DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground;

            pre = pre & paintParts;

            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, pre);

            // Paint content
            if (!IsInEditMode && (paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground)
            {
                Color_ color = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;

                TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.TextBoxControl;
                flags |= AlignmentToFlags(cellStyle.Alignment);

                Rectangle_ contentbounds = cellBounds;

                contentbounds.Height -= 2;
                contentbounds.Width  -= 2;

                // If we are top aligned, give ourselves some padding from the top
                if (((int)cellStyle.Alignment & 7) > 0)
                {
                    contentbounds.Offset(0, 2);
                    contentbounds.Height -= 2;
                }

                if (formattedValue != null)
                {
                    TextRenderer.DrawText(graphics, formattedValue.ToString(), cellStyle.Font, contentbounds, color, flags);
                }
            }

            // Postpaint
            DataGridViewPaintParts post = DataGridViewPaintParts.Border | DataGridViewPaintParts.Focus | DataGridViewPaintParts.ErrorIcon;

            post = post & paintParts;

            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, post);
        }
示例#6
0
        public virtual void DrawFlatHotCheckBox(Graphics g, Rectangle_ bounds, Color_ backColor, Color_ foreColor, CheckState state)
        {
            Rectangle_ checkbox_rectangle;
            Rectangle_ fill_rectangle;

            // set up our rectangles first
            // clip two pixels from bottom right for non popup rendered checkboxes
            checkbox_rectangle = new Rectangle_(bounds.X, bounds.Y, Math.Max(bounds.Width - 2, 0), Math.Max(bounds.Height - 2, 0));
            fill_rectangle     = new Rectangle_(checkbox_rectangle.X + 1, checkbox_rectangle.Y + 1, Math.Max(checkbox_rectangle.Width - 2, 0), Math.Max(checkbox_rectangle.Height - 2, 0));

            g.FillRectangle(ResPool.GetSolidBrush(backColor), fill_rectangle);
            ControlPaint.DrawBorder(g, checkbox_rectangle, foreColor, ButtonBorderStyle.Solid);

            bounds.Offset(-1, 0);

            if (state == CheckState.Checked)
            {
                DrawCheck(g, bounds, Color_.Black);
            }
            else if (state == CheckState.Indeterminate)
            {
                DrawCheck(g, bounds, SystemColors.ControlDarkDark);
            }
        }
示例#7
0
        internal static void DrawTextInternal(IDeviceContext dc, string text, Font font, Rectangle_ bounds, Color_ foreColor, Color_ backColor, TextFormatFlags flags, bool useDrawString)
        {
            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }

            if (text == null || text.Length == 0)
            {
                return;
            }

            // We use MS GDI API's unless told not to, or we aren't on Windows
            if (!useDrawString && XplatUI.RunningOnUnix)
            {
                if ((flags & TextFormatFlags.VerticalCenter) == TextFormatFlags.VerticalCenter || (flags & TextFormatFlags.Bottom) == TextFormatFlags.Bottom)
                {
                    flags |= TextFormatFlags.SingleLine;
                }

                // Calculate the text bounds (there is often padding added)
                Rectangle_ new_bounds = PadRectangle(bounds, flags);
                new_bounds.Offset((int)(dc as Graphics).Transform.OffsetX, (int)(dc as Graphics).Transform.OffsetY);

                IntPtr hdc = IntPtr.Zero;
                bool   clear_clip_region = false;

                // If we need to use the graphics clipping region, add it to our hdc
                if ((flags & TextFormatFlags.PreserveGraphicsClipping) == TextFormatFlags.PreserveGraphicsClipping)
                {
                    Graphics graphics    = (Graphics)dc;
                    Region   clip_region = graphics.Clip;

                    if (!clip_region.IsInfinite(graphics))
                    {
                        IntPtr hrgn = clip_region.GetHrgn(graphics);
                        hdc = dc.GetHdc();
                        SelectClipRgn(hdc, hrgn);
                        DeleteObject(hrgn);

                        clear_clip_region = true;
                    }
                }

                if (hdc == IntPtr.Zero)
                {
                    hdc = dc.GetHdc();
                }

                // Set the fore color
                if (foreColor != Color_.Empty)
                {
                    SetTextColor(hdc, ColorTranslator.ToWin32(foreColor));
                }

                // Set the back color
                if (backColor != Color_.Transparent && backColor != Color_.Empty)
                {
                    SetBkMode(hdc, 2);                          //1-Transparent, 2-Opaque
                    SetBkColor(hdc, ColorTranslator.ToWin32(backColor));
                }
                else
                {
                    SetBkMode(hdc, 1);                          //1-Transparent, 2-Opaque
                }

                XplatUIWin32.RECT r = XplatUIWin32.RECT.FromRectangle(new_bounds);

                IntPtr prevobj;

                if (font != null)
                {
                    prevobj = SelectObject(hdc, font.ToHfont());
                    Win32DrawText(hdc, text, text.Length, ref r, (int)flags);
                    prevobj = SelectObject(hdc, prevobj);
                    DeleteObject(prevobj);
                }
                else
                {
                    Win32DrawText(hdc, text, text.Length, ref r, (int)flags);
                }

                if (clear_clip_region)
                {
                    SelectClipRgn(hdc, IntPtr.Zero);
                }

                dc.ReleaseHdc();
            }
            // Use Graphics.DrawString as a fallback method
            else
            {
                Graphics g;
                IntPtr   hdc = IntPtr.Zero;

                if (dc is Graphics)
                {
                    g = (Graphics)dc;
                }
                else
                {
                    hdc = dc.GetHdc();
                    g   = Graphics.FromHdc(hdc);
                }

                StringFormat sf = FlagsToStringFormat(flags);

                Rectangle_ new_bounds = PadDrawStringRectangle(bounds, flags);

                g.DrawString(text, font, ThemeEngine.Current.ResPool.GetSolidBrush(foreColor), new_bounds, sf);

                if (!(dc is Graphics))
                {
                    g.Dispose();
                    dc.ReleaseHdc();
                }
            }
        }