コード例 #1
0
        // Render the splitter buttons based on system capability and button style
        private void DrawSplitterButtons(Graphics g)
        {
            if (splitterButtonStyle == ButtonStyle.Image)
            {
                if (!panel1Minimized)
                {
                    if (splitterVertical)
                    {
                        g.DrawImage(splitterButtonBitmap, rectLeftDown);
                    }
                    else
                    {
                        g.DrawImage(bitmapUp, rectRightUp);
                    }
                }

                if (!panel2Minimized)
                {
                    if (splitterVertical)
                    {
                        g.DrawImage(bitmapRight, rectRightUp);
                    }
                    else
                    {
                        g.DrawImage(bitmapDown, rectLeftDown);
                    }
                }
            }
            else if (splitterButtonStyle == ButtonStyle.PushButton)
            {
                // Map ScrollBarArrowButtonStates to PushButtonStates
                PushButtonState pbs1 = (PushButtonState)((int)button1State & 3);
                PushButtonState pbs2 = (PushButtonState)((int)button2State & 3);

                if (!panel1Minimized)
                {
                    if (splitterVertical)
                    {
                        ButtonRenderer.DrawButton(g, rectLeftDown, pbs1);
                    }
                    else
                    {
                        ButtonRenderer.DrawButton(g, rectRightUp, pbs1);
                    }

                    if (splitterButtonBitmap != null)
                    {
                        if (splitterVertical)
                        {
                            g.DrawImage(splitterButtonBitmap, rectLeftDown);
                        }
                        else
                        {
                            g.DrawImage(bitmapUp, rectRightUp);
                        }
                    }
                }

                if (!panel2Minimized)
                {
                    if (splitterVertical)
                    {
                        ButtonRenderer.DrawButton(g, rectRightUp, pbs2);
                    }
                    else
                    {
                        ButtonRenderer.DrawButton(g, rectLeftDown, pbs2);
                    }

                    if (splitterButtonBitmap != null)
                    {
                        if (splitterVertical)
                        {
                            g.DrawImage(bitmapRight, rectRightUp);
                        }
                        else
                        {
                            g.DrawImage(bitmapDown, rectLeftDown);
                        }
                    }
                }
            }
            else if (ScrollBarRenderer.IsSupported && splitterButtonStyle == ButtonStyle.ScrollBar)
            {
                if (!panel1Minimized)
                {
                    if (splitterVertical)
                    {
                        ScrollBarRenderer.DrawArrowButton(g, rectLeftDown, button1State);
                    }
                    else
                    {
                        ScrollBarRenderer.DrawArrowButton(g, rectRightUp, button1State);
                    }
                }

                if (!panel2Minimized)
                {
                    if (splitterVertical)
                    {
                        ScrollBarRenderer.DrawArrowButton(g, rectRightUp, button2State);
                    }
                    else
                    {
                        ScrollBarRenderer.DrawArrowButton(g, rectLeftDown, button2State);
                    }
                }
            }
        }
コード例 #2
0
        protected override void Paint
        (
            Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates elementState,
            object value,
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts
        )
        {
            if (!this.enabledValue)
            {
                if
                (
                    (paintParts & DataGridViewPaintParts.Background)
                    ==
                    DataGridViewPaintParts.Background
                )
                {
                    SolidBrush cellBackground = new SolidBrush(cellStyle.BackColor);
                    graphics.FillRectangle(cellBackground, cellBounds);
                    cellBackground.Dispose();
                }

                if
                (
                    (paintParts & DataGridViewPaintParts.Border)
                    ==
                    DataGridViewPaintParts.Border
                )
                {
                    PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
                }

                Rectangle buttonArea       = cellBounds;
                Rectangle buttonAdjustment = this.BorderWidths(advancedBorderStyle);
                buttonArea.X      += buttonAdjustment.X;
                buttonArea.Y      += buttonAdjustment.Y;
                buttonArea.Height -= buttonAdjustment.Height;
                buttonArea.Width  -= buttonAdjustment.Width;

                ButtonRenderer.DrawButton
                    (graphics,
                    buttonArea,
                    System.Windows.Forms.VisualStyles.PushButtonState.Disabled);

                if (this.FormattedValue is String)
                {
                    TextRenderer.DrawText(graphics,
                                          (string)this.FormattedValue,
                                          this.DataGridView.Font,
                                          buttonArea,
                                          SystemColors.GrayText);
                }
            }
            else
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                           elementState, value, formattedValue, errorText,
                           cellStyle, advancedBorderStyle, paintParts);
            }//if outside
        }
コード例 #3
0
ファイル: SplitButton.cs プロジェクト: jmptrader/Creek
        /// <summary>
        /// Dessine le bouton dans le context donné
        /// </summary>
        /// <param name="pevent"></param>
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (!showSplit)
            {
                return;
            }

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = ClientRectangle;

            // draw the button background as according to the current state.
            if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
            {
                Rectangle backgroundBounds = bounds;
                backgroundBounds.Inflate(-1, -1);
                ButtonRenderer.DrawButton(g, backgroundBounds, State);

                // button renderer doesnt draw the black frame when themes are off =(
                g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);
            }
            else
            {
                ButtonRenderer.DrawButton(g, bounds, State);
            }
            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - PushButtonWidth - 1, BorderSize, PushButtonWidth,
                                              bounds.Height - BorderSize * 2);

            int internalBorder = BorderSize;
            var focusRect      =
                new Rectangle(internalBorder,
                              internalBorder,
                              bounds.Width - dropDownRectangle.Width - internalBorder,
                              bounds.Height - (internalBorder * 2));

            bool drawSplitLine = !showSplitOnlyOnFocus ||
                                 (State == PushButtonState.Hot || State == PushButtonState.Pressed ||
                                  !Application.RenderWithVisualStyles);

            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X = bounds.Left + 1;
                focusRect.X         = dropDownRectangle.Right;
                if (drawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Left + PushButtonWidth, BorderSize,
                               bounds.Left + PushButtonWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Left + PushButtonWidth + 1, BorderSize,
                               bounds.Left + PushButtonWidth + 1, bounds.Bottom - BorderSize);
                }
            }
            else
            {
                if (drawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Right - PushButtonWidth, BorderSize,
                               bounds.Right - PushButtonWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Right - PushButtonWidth - 1, BorderSize,
                               bounds.Right - PushButtonWidth - 1, bounds.Bottom - BorderSize);
                }
            }

            // Draw an arrow in the correct location
            PaintArrow(g, dropDownRectangle);

            // Figure out how to draw the text
            TextFormatFlags formatFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;

            // If we dont' use mnemonic, set formatFlag to NoPrefix as this will show ampersand.
            if (!UseMnemonic)
            {
                formatFlags = formatFlags | TextFormatFlags.NoPrefix;
            }
            else if (!ShowKeyboardCues)
            {
                formatFlags = formatFlags | TextFormatFlags.HidePrefix;
            }

            if (!string.IsNullOrEmpty(Text))
            {
                TextRenderer.DrawText(g, Text, Font, focusRect, SystemColors.ControlText, formatFlags);
            }

            // draw the focus rectangle.

            if (State != PushButtonState.Pressed && Focused && !Application.RenderWithVisualStyles)
            {
                ControlPaint.DrawFocusRectangle(g, focusRect);
            }

            // Draw image
            if (Image != null)
            {
                ((Bitmap)Image).MakeTransparent();
                pevent.Graphics.DrawImage(Image, ComputeImageRectangle(focusRect));
            }
        }
コード例 #4
0
        private void PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds, bool up)
        {
            PushButtonState pbState = DetermineState(up);

            // First handle transparent case

            if (ButtonRenderer.IsBackgroundPartiallyTransparent(pbState))
            {
                ButtonRenderer.DrawParentBackground(e.Graphics, bounds, Control);
            }

            // Now draw the actual themed background
            if (!DpiHelper.IsScalingRequirementMet)
            {
                ButtonRenderer.DrawButton(e.Graphics, Control.ClientRectangle, false, pbState);
            }
            else
            {
                ButtonRenderer.DrawButtonForHandle(e.Graphics, Control.ClientRectangle, false, pbState, Control.HandleInternal);
            }

            // Now overlay the background image or backcolor (the former overrides the latter), leaving a
            // margin. We hardcode this margin for now since GetThemeMargins returns 0 all the
            // time.
            // Changing this because GetThemeMargins simply does not
            // work in some cases.
            bounds.Inflate(-buttonBorderSize, -buttonBorderSize);


            //only paint if the user said not to use the themed backcolor.
            if (!Control.UseVisualStyleBackColor)
            {
                bool  painted = false;
                bool  isHighContrastHighlighted = up && IsHighContrastHighlighted();
                Color color = isHighContrastHighlighted ? SystemColors.Highlight : Control.BackColor;

                // Note: PaintEvent.HDC == 0 if GDI+ has used the HDC -- it wouldn't be safe for us
                // to use it without enough bookkeeping to negate any performance gain of using GDI.
                if (color.A == 255 && e.HDC != IntPtr.Zero)
                {
                    if (DisplayInformation.BitsPerPixel > 8)
                    {
                        NativeMethods.RECT r = new NativeMethods.RECT(bounds.X, bounds.Y, bounds.Right, bounds.Bottom);
                        // SysColorBrush does not have to be deleted.
                        SafeNativeMethods.FillRect(new HandleRef(e, e.HDC), ref r, new HandleRef(this,
                                                                                                 isHighContrastHighlighted ? SafeNativeMethods.GetSysColorBrush(ColorTranslator.ToOle(color) & 0xFF) : Control.BackColorBrush));
                        painted = true;
                    }
                }

                if (!painted)
                {
                    // don't paint anything from 100% transparent background
                    //
                    if (color.A > 0)
                    {
                        if (color.A == 255)
                        {
                            color = e.Graphics.GetNearestColor(color);
                        }

                        // Color has some transparency or we have no HDC, so we must
                        // fall back to using GDI+.
                        //
                        using (Brush brush = new SolidBrush(color))
                        {
                            e.Graphics.FillRectangle(brush, bounds);
                        }
                    }
                }
            }

            //This code is mostly taken from the non-themed rendering code path.
            if (Control.BackgroundImage != null && !DisplayInformation.HighContrast)
            {
                ControlPaint.DrawBackgroundImage(e.Graphics, Control.BackgroundImage, Color.Transparent, Control.BackgroundImageLayout, Control.ClientRectangle, bounds, Control.DisplayRectangle.Location, Control.RightToLeft);
            }
        }
コード例 #5
0
        /// <summary>
        /// Paints the column header cell, including the drop-down button.
        /// </summary>
        /// <param name="graphics">The Graphics used to paint the DataGridViewCell.</param>
        /// <param name="clipBounds">A Rectangle that represents the area of the DataGridView that needs to be repainted.</param>
        /// <param name="cellBounds">A Rectangle that contains the bounds of the DataGridViewCell that is being painted.</param>
        /// <param name="rowIndex">The row index of the cell that is being painted.</param>
        /// <param name="cellState">A bitwise combination of DataGridViewElementStates values that specifies the state of the cell.</param>
        /// <param name="value">The data of the DataGridViewCell that is being painted.</param>
        /// <param name="formattedValue">The formatted data of the DataGridViewCell that is being painted.</param>
        /// <param name="errorText">An error message that is associated with the cell.</param>
        /// <param name="cellStyle">A DataGridViewCellStyle that contains formatting and style information about the cell.</param>
        /// <param name="advancedBorderStyle">A DataGridViewAdvancedBorderStyle that contains border styles for the cell that is being painted.</param>
        /// <param name="paintParts">A bitwise combination of the DataGridViewPaintParts values that specifies which parts of the cell need to be painted.</param>
        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)
        {
            CheckMenuItemWidths(graphics);

            // Use the base method to paint the default appearance.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue,
                       errorText, cellStyle, advancedBorderStyle, paintParts);

            // Continue only if ContentBackground is part of the paint request.
            if ((paintParts & DataGridViewPaintParts.ContentBackground) == 0)
            {
                return;
            }

            // Retrieve the current button bounds.
            var buttonBounds = DropDownButtonBounds;

            // Continue only if the buttonBounds is big enough to draw.
            if (buttonBounds.Width < 1 || buttonBounds.Height < 1)
            {
                return;
            }

            // Paint the button manually or using visual styles if visual styles
            // are enabled, using the correct state depending on whether the
            // filter list is showing and whether there is a filter in effect
            // for the current column.
            if (Application.RenderWithVisualStyles)
            {
                var state = ComboBoxState.Normal;

                if (m_dropDownListBoxShowing)
                {
                    state = ComboBoxState.Pressed;
                }

                ComboBoxRenderer.DrawDropDownButton(
                    graphics, buttonBounds, state);
            }
            else
            {
                // Determine the pressed state in order to paint the button
                // correctly and to offset the down arrow.
                var pressedOffset = 0;
                var state         = PushButtonState.Normal;
                if (m_dropDownListBoxShowing)
                {
                    state         = PushButtonState.Pressed;
                    pressedOffset = 1;
                }
                ButtonRenderer.DrawButton(graphics, buttonBounds, state);

                graphics.FillPolygon(SystemBrushes.ControlText, new[] {
                    new Point(
                        buttonBounds.Width / 2 +
                        buttonBounds.Left - 1 + pressedOffset,
                        buttonBounds.Height * 3 / 4 +
                        buttonBounds.Top - 1 + pressedOffset),
                    new Point(
                        buttonBounds.Width / 4 +
                        buttonBounds.Left + pressedOffset,
                        buttonBounds.Height / 2 +
                        buttonBounds.Top - 1 + pressedOffset),
                    new Point(
                        buttonBounds.Width * 3 / 4 +
                        buttonBounds.Left - 1 + pressedOffset,
                        buttonBounds.Height / 2 +
                        buttonBounds.Top - 1 + pressedOffset)
                });
            }
        }
コード例 #6
0
        public int DrawSelf(Graphics g, Rectangle Bounds, int visibleTop, int visibleBottom)
        {
            if (Bounds.Width == RowWidth && !(Bounds.Top < visibleBottom && Bounds.Top + RowHeight > visibleTop))
            {
                return(RowHeight);
            }

            int top  = Bounds.Top + ItemPadding.Top + InternalPadding.Top;
            int left = Bounds.Left + InternalPadding.Left;

            int rowheight1 = HeightOf(Title, TitleFont, ParentPanel.col2 + col3) + ItemPadding.Vertical;
            int rowheight2 = HeightOf(Description, Font, col3) + ItemPadding.Vertical;
            int rowheight3 = ShowTime ? HeightOf(TimeTaken, Font, col3) + ItemPadding.Vertical : 0;
            int rowheight4 = ShowProgress ? 17 + ItemPadding.Vertical : 0;

            RowHeight = rowheight1 + rowheight2 + rowheight3 + rowheight4 + InternalPadding.Vertical;
            RowWidth  = Bounds.Width;

            if (g != null && Bounds.Top < visibleBottom && Bounds.Top + RowHeight > visibleTop && Bounds.Top + RowHeight <= Int16.MaxValue)
            {
                int left1 = left + col1;
                int left2 = left1 + ParentPanel.col2;
                int left3 = left2 + col3;
                int top1  = top + rowheight1;
                int top2  = top1 + rowheight2;
                int top3  = top2 + rowheight3;

                g.FillRectangle(BackBrush, Bounds.Left, Bounds.Top, RowWidth, RowHeight);
                if (!Error)
                {
                    g.DrawRectangle(BorderPen, Bounds.Left, Bounds.Top, RowWidth, RowHeight);
                }
                else
                {
                    g.DrawLine(ErrorPenThin, Bounds.Left, Bounds.Top, Bounds.Left + RowWidth, Bounds.Top);
                    g.DrawLine(ErrorPenThin, Bounds.Left, Bounds.Top + RowHeight, Bounds.Left + RowWidth, Bounds.Top + RowHeight);
                    g.DrawLine(ErrorPenThick, Bounds.Left + RowWidth, Bounds.Top, Bounds.Left + RowWidth, Bounds.Top + RowHeight + 1);
                    g.DrawLine(ErrorPenThick, Bounds.Left, Bounds.Top, Bounds.Left, Bounds.Top + RowHeight + 1);
                }

                g.DrawImage(Image, left + ((col1 - Image.Width) / 2), top, Image.Width, Image.Height);
                Drawing.DrawText(g, Title, TitleFont, new Rectangle(left1, top, ParentPanel.col2 + col3, rowheight1), TitleColor, TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
                Drawing.DrawText(g, TimeOccurred, Font, new Point(left3, top), TextColor);
                if (!Error)
                {
                    Drawing.DrawText(g, DescriptionLabel, Font, new Point(left1, top1), TextColor);
                }
                else
                {
                    Drawing.DrawText(g, ErrorLabel, Font, new Point(left1, top1), ErrorColor);
                }

                Drawing.DrawText(g, Description, Font, new Rectangle(left2, top1, col3, rowheight2), TextColor, TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);

                if (ShowCancel)
                {
                    if (Application.RenderWithVisualStyles)
                    {
                        Rectangle       r     = new Rectangle(left3, top1, 75, 23);
                        PushButtonState state =
                            CancelEnabled && ButtonPressed ? PushButtonState.Pressed :
                            CancelEnabled                  ? PushButtonState.Normal :
                            PushButtonState.Disabled;
                        ButtonRenderer.DrawButton(g, r, Messages.CANCEL, Font, false, state);
                    }
                    else
                    {
                        if (CancelEnabled && !ButtonPressed)
                        {
                            g.FillRectangle(SystemBrushes.ControlText, new Rectangle(left3, top1, 75, 23));
                            g.FillRectangle(SystemBrushes.ButtonHighlight, new Rectangle(left3, top1, 74, 22));
                            g.FillRectangle(SystemBrushes.ButtonShadow, new Rectangle(left3 + 1, top1 + 1, 73, 21));
                            g.FillRectangle(SystemBrushes.ButtonFace, new Rectangle(left3 + 1, top1 + 1, 72, 20));
                            Drawing.DrawText(g, Messages.CANCEL, Font, new Rectangle(left3 + 1, top1 + 1, 72, 20), SystemColors.ControlText, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                        }
                        else if (CancelEnabled)
                        {
                            g.FillRectangle(SystemBrushes.ControlText, new Rectangle(left3, top1, 75, 23));
                            g.FillRectangle(SystemBrushes.ButtonShadow, new Rectangle(left3 + 1, top1 + 1, 73, 21));
                            g.FillRectangle(SystemBrushes.ButtonFace, new Rectangle(left3 + 2, top1 + 2, 71, 19));
                            Drawing.DrawText(g, Messages.CANCEL, Font, new Rectangle(left3 + 2, top1 + 2, 71, 19), SystemColors.ControlText, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                        }
                        else
                        {
                            g.FillRectangle(SystemBrushes.ControlText, new Rectangle(left3, top1, 75, 23));
                            g.FillRectangle(SystemBrushes.ButtonHighlight, new Rectangle(left3, top1, 74, 22));
                            g.FillRectangle(SystemBrushes.ButtonShadow, new Rectangle(left3 + 1, top1 + 1, 73, 21));
                            g.FillRectangle(SystemBrushes.ButtonFace, new Rectangle(left3 + 1, top1 + 1, 72, 20));
                            Drawing.DrawText(g, Messages.CANCEL, Font, new Rectangle(left3 + 1, top1 + 1, 72, 20), SystemColors.GrayText, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
                        }
                    }
                }

                if (ShowTime)
                {
                    Drawing.DrawText(g, TimeLabel, Font, new Point(left1, top2), TextColor);
                    Drawing.DrawText(g, TimeTaken, Font, new Rectangle(left2, top2, col3, rowheight3), TextColor, TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl);
                }

                if (ShowProgress)
                {
                    if (Application.RenderWithVisualStyles)
                    {
                        Drawing.DrawText(g, ProgressLabel, Font, new Point(left1, top3), TextColor);
                        ProgressBarRenderer.DrawHorizontalBar(g, new Rectangle(left2, top3, col3, 17));
                        ProgressBarRenderer.DrawHorizontalChunks(g, new Rectangle(left2 + 4, top3 + 3, (Progress * (col3 - 8) / 100), 12));
                    }
                    else
                    {
                        Drawing.DrawText(g, ProgressLabel, Font, new Point(left1, top3), TextColor);
                        g.FillRectangle(SystemBrushes.ButtonShadow, new Rectangle(left2, top3, col3, 17));
                        g.FillRectangle(SystemBrushes.ButtonHighlight, new Rectangle(left2 + 1, top3 + 1, col3 - 1, 16));
                        g.FillRectangle(SystemBrushes.ButtonFace, new Rectangle(left2 + 1, top3 + 1, col3 - 2, 15));
                        int barwidth   = (Progress * (col3 - 4) / 100);
                        int chunkwidth = 7;
                        int chunkgap   = 2;
                        int progleft   = 0;
                        while (true)
                        {
                            if (progleft + chunkwidth + chunkgap < barwidth)
                            {
                                g.FillRectangle(SystemBrushes.ActiveCaption, new Rectangle(left2 + 2 + progleft, top3 + 2, chunkwidth, 13));
                                progleft += chunkwidth + chunkgap;
                            }
                            else
                            {
                                break;
                            }
                        }
                        g.FillRectangle(SystemBrushes.ActiveCaption, new Rectangle(left2 + 2 + progleft, top3 + 2, chunkwidth - progleft, 13));
                    }
                }
            }

            return(RowHeight);
        }
コード例 #7
0
        /// <summary>
        /// Paints the column header cell, including the drop-down button.
        /// </summary>
        /// <param name="graphics">The Graphics used to paint the DataGridViewCell.</param>
        /// <param name="clipBounds">A Rectangle that represents the area of the DataGridView that needs to be repainted.</param>
        /// <param name="cellBounds">A Rectangle that contains the bounds of the DataGridViewCell that is being painted.</param>
        /// <param name="rowIndex">The row index of the cell that is being painted.</param>
        /// <param name="cellState">A bitwise combination of DataGridViewElementStates values that specifies the state of the cell.</param>
        /// <param name="value">The data of the DataGridViewCell that is being painted.</param>
        /// <param name="formattedValue">The formatted data of the DataGridViewCell that is being painted.</param>
        /// <param name="errorText">An error message that is associated with the cell.</param>
        /// <param name="cellStyle">A DataGridViewCellStyle that contains formatting and style information about the cell.</param>
        /// <param name="advancedBorderStyle">A DataGridViewAdvancedBorderStyle that contains border styles for the cell that is being painted.</param>
        /// <param name="paintParts">A bitwise combination of the DataGridViewPaintParts values that specifies which parts of the cell need to be painted.</param>
        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)
        {
            // Use the base method to paint the default appearance.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                       cellState, value, formattedValue,
                       errorText, cellStyle, advancedBorderStyle, paintParts);

            // Continue only if filtering is enabled and ContentBackground is
            // part of the paint request.
            if (!FilteringEnabled ||
                (paintParts & DataGridViewPaintParts.ContentBackground) == 0)
            {
                return;
            }

            // Retrieve the current button bounds.
            Rectangle buttonBounds = DropDownButtonBounds;

            // Continue only if the buttonBounds is big enough to draw.
            if (buttonBounds.Width < 1 || buttonBounds.Height < 1)
            {
                return;
            }

            // Paint the button manually or using visual styles if visual styles
            // are enabled, using the correct state depending on whether the
            // filter list is showing and whether there is a filter in effect
            // for the current column.
            if (Application.RenderWithVisualStyles)
            {
                ComboBoxState state = ComboBoxState.Normal;

                if (filterControlShowing)
                {
                    state = ComboBoxState.Pressed;
                }
                else if (filtered)
                {
                    state = ComboBoxState.Hot;
                }
                ComboBoxRenderer.DrawDropDownButton(
                    graphics, buttonBounds, state);

                Int32 pressedOffset = 0;
                if (filterControlShowing)
                {
                    pressedOffset = 1;
                }



                // If there is a filter in effect for the column, paint the
                // down arrow as an unfilled triangle. If there is no filter
                // in effect, paint the down arrow as a filled triangle.
                if (filtered)
                {
                    buttonBounds.Width  += 6;
                    buttonBounds.Height += 7;
                    buttonBounds.Offset(-2, -2);

                    if (false)
                    {
                        Pen drawPen = new Pen(Program.Colors.GetColor(GUIColors.ColorNames.Marked_BackColor));
                        graphics.DrawPolygon(drawPen, new Point[] {
                            new Point(
                                buttonBounds.Width / 2 +
                                buttonBounds.Left - 1 + pressedOffset,
                                buttonBounds.Height * 3 / 4 +
                                buttonBounds.Top - 1 + pressedOffset),
                            new Point(
                                buttonBounds.Width / 4 +
                                buttonBounds.Left + pressedOffset,
                                buttonBounds.Height / 2 +
                                buttonBounds.Top - 1 + pressedOffset),
                            new Point(
                                buttonBounds.Width * 3 / 4 +
                                buttonBounds.Left - 1 + pressedOffset,
                                buttonBounds.Height / 2 +
                                buttonBounds.Top - 1 + pressedOffset)
                        });
                    }
                    else
                    {
                        Brush drawBrush = new SolidBrush(Program.Colors.GetColor(GUIColors.ColorNames.Marked_BackColor));

                        graphics.FillPolygon(drawBrush, new Point[] {
                            new Point(
                                buttonBounds.Width / 2 +
                                buttonBounds.Left - 1 + pressedOffset,
                                buttonBounds.Height * 3 / 4 +
                                buttonBounds.Top - 1 + pressedOffset),
                            new Point(
                                buttonBounds.Width / 4 +
                                buttonBounds.Left + pressedOffset,
                                buttonBounds.Height / 2 +
                                buttonBounds.Top - 1 + pressedOffset),
                            new Point(
                                buttonBounds.Width * 3 / 4 +
                                buttonBounds.Left - 1 + pressedOffset,
                                buttonBounds.Height / 2 +
                                buttonBounds.Top - 1 + pressedOffset)
                        });
                    }
                }

                //else
                //{
                //    graphics.FillPolygon(SystemBrushes.ControlText, new Point[] {
                //        new Point(
                //            buttonBounds.Width / 2 +
                //                buttonBounds.Left - 1 + pressedOffset,
                //            buttonBounds.Height * 3 / 4 +
                //                buttonBounds.Top - 1 + pressedOffset),
                //        new Point(
                //            buttonBounds.Width / 4 +
                //                buttonBounds.Left + pressedOffset,
                //            buttonBounds.Height / 2 +
                //                buttonBounds.Top - 1 + pressedOffset),
                //        new Point(
                //            buttonBounds.Width * 3 / 4 +
                //                buttonBounds.Left - 1 + pressedOffset,
                //            buttonBounds.Height / 2 +
                //                buttonBounds.Top - 1 + pressedOffset)
                //    });
                //}
            }
            else
            {
                // Determine the pressed state in order to paint the button
                // correctly and to offset the down arrow.
                Int32           pressedOffset = 0;
                PushButtonState state         = PushButtonState.Normal;
                if (filterControlShowing)
                {
                    state         = PushButtonState.Pressed;
                    pressedOffset = 1;
                }
                ButtonRenderer.DrawButton(graphics, buttonBounds, state);

                // If there is a filter in effect for the column, paint the
                // down arrow as an unfilled triangle. If there is no filter
                // in effect, paint the down arrow as a filled triangle.
                if (filtered)
                {
                    graphics.DrawPolygon(SystemPens.ControlText, new Point[] {
                        new Point(
                            buttonBounds.Width / 2 +
                            buttonBounds.Left - 1 + pressedOffset,
                            buttonBounds.Height * 3 / 4 +
                            buttonBounds.Top - 1 + pressedOffset),
                        new Point(
                            buttonBounds.Width / 4 +
                            buttonBounds.Left + pressedOffset,
                            buttonBounds.Height / 2 +
                            buttonBounds.Top - 1 + pressedOffset),
                        new Point(
                            buttonBounds.Width * 3 / 4 +
                            buttonBounds.Left - 1 + pressedOffset,
                            buttonBounds.Height / 2 +
                            buttonBounds.Top - 1 + pressedOffset)
                    });
                }
                else
                {
                    graphics.FillPolygon(SystemBrushes.ControlText, new Point[] {
                        new Point(
                            buttonBounds.Width / 2 +
                            buttonBounds.Left - 1 + pressedOffset,
                            buttonBounds.Height * 3 / 4 +
                            buttonBounds.Top - 1 + pressedOffset),
                        new Point(
                            buttonBounds.Width / 4 +
                            buttonBounds.Left + pressedOffset,
                            buttonBounds.Height / 2 +
                            buttonBounds.Top - 1 + pressedOffset),
                        new Point(
                            buttonBounds.Width * 3 / 4 +
                            buttonBounds.Left - 1 + pressedOffset,
                            buttonBounds.Height / 2 +
                            buttonBounds.Top - 1 + pressedOffset)
                    });
                }
            }
        }
コード例 #8
0
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates elementState, object value,
                                      object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            // The button cell is disabled, so paint the border,
            // background, and disabled button for the cell.
            if (!this.enabledValue)
            {
                // Draw the cell background, if specified.
                if ((paintParts & DataGridViewPaintParts.Background) ==
                    DataGridViewPaintParts.Background)
                {
                    SolidBrush cellBackground =
                        new SolidBrush(cellStyle.BackColor);
                    graphics.FillRectangle(cellBackground, cellBounds);
                    cellBackground.Dispose();
                }

                // Draw the cell borders, if specified.
                if ((paintParts & DataGridViewPaintParts.Border) ==
                    DataGridViewPaintParts.Border)
                {
                    PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
                                advancedBorderStyle);
                }

                // Calculate the area in which to draw the button.
                Rectangle buttonArea       = cellBounds;
                Rectangle buttonAdjustment =
                    this.BorderWidths(advancedBorderStyle);
                buttonArea.X      += buttonAdjustment.X;
                buttonArea.Y      += buttonAdjustment.Y;
                buttonArea.Height -= buttonAdjustment.Height;
                buttonArea.Width  -= buttonAdjustment.Width;

                // Draw the disabled button.
                ButtonRenderer.DrawButton(graphics, buttonArea,
                                          PushButtonState.Disabled);

                // Draw the disabled button text.
                if (this.FormattedValue is String)
                {
                    TextRenderer.DrawText(graphics,
                                          (string)this.FormattedValue,
                                          this.DataGridView.Font,
                                          buttonArea, SystemColors.GrayText);
                }
            }
            else
            {
                // The button cell is enabled, so let the base class
                // handle the painting.
                base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                           elementState, value, formattedValue, errorText,
                           cellStyle, advancedBorderStyle, paintParts);
            }
        }
コード例 #9
0
        public void DrawPlayerLine(Graphics g, Rectangle bounds, Color foreColor, Color backColor, bool grayedOut, bool isBattle)
        {
            if (isDummy)
            {
                return;
            }

            g.TextRenderingHint = TextRenderingHint.SystemDefault;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            var x = 0;

            if (grayedOut)
            {
                foreColor = Program.Conf.FadeColor;
            }

            Action <Image> drawImage = image =>
            {
                g.DrawImage(image, bounds.Left + x, bounds.Top, 16, 16);
                x += 19;
            };

            Action <string, Color, Color> drawText = (text, fore, back) =>
            {
                TextRenderer.DrawText(g, text, font, new Point(bounds.Left + x, bounds.Top), fore, back);
                x += TextRenderer.MeasureText(g, text, font).Width;
            };

            // is section header
            if (Title != null)
            {
                font = boldFont;
                if (Title == "Search results:")
                {
                    drawImage(ZklResources.search);
                }
                TextRenderer.DrawText(g, Title, font, bounds, foreColor, backColor, TextFormatFlags.HorizontalCenter);
                return;
            }

            // is button
            if (Button != null)
            {
                font = boldFont;
                ButtonRenderer.DrawButton(g, bounds, Button, font, false, PushButtonState.Normal);
                return;
            }

            // is player slot
            if (SlotButton != null)
            {
                var slotText = string.Format("Empty Slot: {0} {1}", MissionSlot.TeamName, MissionSlot.IsRequired ? "(Required)" : String.Empty);
                var color    = ((MyCol)MissionSlot.Color);
                if (!IsZeroKBattle)
                {
                    using (var brush = new SolidBrush(Color.FromArgb(color.R, color.G, color.B)))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.FillEllipse(brush, x, bounds.Top, bounds.Bottom - bounds.Top, bounds.Bottom - bounds.Top);
                    }
                }
                x += bounds.Bottom - bounds.Top + 2;
                drawText(slotText, foreColor, backColor);
                return;
            }

            // is bot
            if (BotBattleStatus != null)
            {
                var bot = BotBattleStatus;
                x += 19;
                drawImage(ZklResources.robot);
                var botDisplayName = MissionSlot == null ? bot.aiLib : MissionSlot.TeamName;
                drawText(botDisplayName + " (" + bot.owner + ")", foreColor, backColor);
                return;
            }

            // is player
            var user       = User;
            var userStatus = UserBattleStatus;

            if (UserName != null && user == null)
            {
                drawText(UserName + " has left.", foreColor, backColor);
                return;
            }

            if (isBattle)
            {
                if (userStatus.IsSpectator && (Program.TasClient.MyBattle == null || !Program.TasClient.MyBattle.IsQueue || Program.TasClient.MyBattle.Founder.Name == userStatus.Name))
                {
                    drawImage(ZklResources.spec);
                }
                else if (userStatus.SyncStatus == SyncStatuses.Synced)
                {
                    drawImage(ZklResources.ready);
                }
                else
                {
                    drawImage(ZklResources.unready);
                }
            }

            drawImage(TextImage.GetUserImage(user.Name));

            Image flag;

            if (Images.CountryFlags.TryGetValue(user.Country, out flag) && flag != null)
            {
                g.DrawImageUnscaled(flag, bounds.Left + x, bounds.Top + 4);
            }
            x += 16;
            x += 2; // margin

            if (!user.IsBot)
            {
                drawImage(Images.GetRank(user.Level));

                var clan = ServerImagesHandler.GetClanOrFactionImage(user);
                if (clan.Item1 != null)
                {
                    drawImage(clan.Item1);
                }
            }

            var userDisplayName = MissionSlot == null ? user.Name : String.Format("{1}: {0}", MissionSlot.TeamName, user.Name);

            drawText(userDisplayName, foreColor, backColor);
            var top10 = Program.SpringieServer.GetTop10Rank(user.Name);

            if (top10 > 0)
            {
                var oldProgression = x;
                drawImage(ZklResources.cup);
                x = oldProgression;
                TextRenderer.DrawText(g, top10.ToString(), boldFont, new Point(bounds.Left + x + 1, bounds.Top), Color.Black, Color.Transparent);
                x += 16;
            }

            if (user.IsInGame)
            {
                drawImage(ZklResources.ingame);
            }
            else if (!isBattle && user.IsInBattleRoom)
            {
                drawImage(ZklResources.battle);
            }

            if (user.IsAway)
            {
                drawImage(ZklResources.away);
            }

            if (isBattle && !userStatus.IsSpectator)
            {
                if (MissionSlot != null)
                {
                    if (userStatus.AllyNumber != MissionSlot.AllyID)
                    {
                        drawText(string.Format("Wrong alliance ({0} instead of {1}).", userStatus.AllyNumber, MissionSlot.AllyID),
                                 Color.Red,
                                 backColor);
                    }
                }
            }

            if (user.SteamID != null)
            {
                bool isEnabled;
                bool isTalking;
                Program.SteamHandler.Voice.GetUserVoiceInfo(user.SteamID.Value, out isEnabled, out isTalking);
                if (isEnabled)
                {
                    drawImage(isTalking ? ZklResources.voice_talking : ZklResources.voice_off);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Primary function for painting the button. This method should be overridden instead of OnPaint.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="bounds">The bounds.</param>
        protected virtual void PaintButton(Graphics graphics, Rectangle bounds)
        {
            System.Diagnostics.Debug.WriteLine($"PaintButton: desMode:{this.IsDesignMode()};vsEnabled:{Application.RenderWithVisualStyles};vsOnOS:{VisualStyleInformation.IsSupportedByOS};btnState:{ButtonState};enabled:{Enabled};imgCt:{(ImageList != null ? ImageList.Images.Count : 0)}");

            if (InitializeRenderer())
            {
                if (OnGlass)
                {
                    rnd.DrawGlassBackground(graphics, bounds, bounds);
                }
                else
                {
                    rnd.DrawParentBackground(graphics, bounds, this);
                    rnd.DrawBackground(graphics, bounds);
                }
            }
            else
            {
                if (ImageList != null && ImageList.Images.Count > 0)
                {
                    int idx = (int)ButtonState - 1;
                    if (ImageList.Images.Count == 1)
                    {
                        idx = 0;
                    }
                    else if (ImageList.Images.Count == 2)
                    {
                        idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                    }
                    else if (ImageList.Images.Count == 3)
                    {
                        idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                    }
                    bool forceDisabled = !Enabled && ImageList.Images.Count == 1;
                    if (OnGlass)
                    {
                        VisualStyleRendererExtension.DrawGlassImage(null, graphics, bounds, ImageList.Images[idx], forceDisabled);
                    }
                    else
                    {
                        if (!Application.RenderWithVisualStyles && VisualStyleInformation.IsSupportedByOS)
                        {
                            System.Drawing.Drawing2D.GraphicsContainer g = graphics.BeginContainer();
                            Rectangle translateRect = bounds;
                            graphics.TranslateTransform(-bounds.Left, -bounds.Top);
                            PaintEventArgs pe = new PaintEventArgs(graphics, translateRect);
                            InvokePaintBackground(Parent, pe);
                            InvokePaint(Parent, pe);
                            graphics.ResetTransform();
                            graphics.EndContainer(g);
                        }
                        else
                        {
                            graphics.Clear(Parent.BackColor);
                        }
                        if (forceDisabled)
                        {
                            ControlPaint.DrawImageDisabled(graphics, ImageList.Images[idx], 0, 0, Color.Transparent);
                        }
                        else
                        {
                            //base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                            //VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, base.ImageList.Images[idx], forceDisabled); // Not 7
                            graphics.DrawImage(ImageList.Images[idx], bounds, bounds, GraphicsUnit.Pixel); // Works on XP, not 7, with Parent.BackColor
                        }
                    }
                }

                /*else if (this.ImageList != null && this.ImageList.Images.Count > 1)
                 *              {
                 *                      int idx = (int)ButtonState - 1;
                 *                      if (this.ImageList.Images.Count == 2)
                 *                              idx = ButtonState == PushButtonState.Disabled ? 1 : 0;
                 *                      if (this.ImageList.Images.Count == 3)
                 *                              idx = ButtonState == PushButtonState.Normal ? 0 : idx - 1;
                 *                      if (rnd != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled())
                 *                              rnd.DrawGlassIcon(graphics, bounds, this.ImageList, idx);
                 *                      else
                 *                              this.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, idx);
                 *              }*/
                // No image so draw standard button
                else
                {
                    ButtonRenderer.DrawParentBackground(graphics, bounds, this);
                    ButtonRenderer.DrawButton(graphics, bounds, ButtonState);
                }
            }

            if (Focused)
            {
                ControlPaint.DrawFocusRectangle(graphics, bounds);
            }
        }
コード例 #11
0
        public static void DrawCommandButton(
            Graphics g,
            PushButtonState state,
            Rectangle rect,
            Color backColor,
            Control childControl)
        {
            VisualStyleElement element = null;
            int alpha = 255;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                const string className = "BUTTON";
                const int    partID    = NativeConstants.BP_COMMANDLINK;
                int          stateID;

                switch (state)
                {
                case PushButtonState.Default:
                    stateID = NativeConstants.CMDLS_DEFAULTED;
                    break;

                case PushButtonState.Disabled:
                    stateID = NativeConstants.CMDLS_DISABLED;
                    break;

                case PushButtonState.Hot:
                    stateID = NativeConstants.CMDLS_HOT;
                    break;

                case PushButtonState.Normal:
                    stateID = NativeConstants.CMDLS_NORMAL;
                    break;

                case PushButtonState.Pressed:
                    stateID = NativeConstants.CMDLS_PRESSED;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }

                try
                {
                    element = VisualStyleElement.CreateElement(className, partID, stateID);

                    if (!VisualStyleRenderer.IsElementDefined(element))
                    {
                        element = null;
                    }
                }
                catch (InvalidOperationException)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                switch (state)
                {
                case PushButtonState.Default:
                    element = VisualStyleElement.Button.PushButton.Default;
                    alpha   = 95;
                    break;

                case PushButtonState.Disabled:
                    element = VisualStyleElement.Button.PushButton.Disabled;
                    break;

                case PushButtonState.Hot:
                    element = VisualStyleElement.Button.PushButton.Hot;
                    break;

                case PushButtonState.Normal:
                    alpha   = 0;
                    element = VisualStyleElement.Button.PushButton.Normal;
                    break;

                case PushButtonState.Pressed:
                    element = VisualStyleElement.Button.PushButton.Pressed;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }
            }

            if (element != null)
            {
                try
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                    renderer.DrawParentBackground(g, rect, childControl);
                    renderer.DrawBackground(g, rect);
                }
                catch (Exception)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                ButtonRenderer.DrawButton(g, rect, state);
            }

            if (alpha != 255)
            {
                using (Brush backBrush = new SolidBrush(Color.FromArgb(255 - alpha, backColor)))
                {
                    CompositingMode oldCM = g.CompositingMode;

                    try
                    {
                        g.CompositingMode = CompositingMode.SourceOver;
                        g.FillRectangle(backBrush, rect);
                    }

                    finally
                    {
                        g.CompositingMode = oldCM;
                    }
                }
            }
        }
コード例 #12
0
        /// <summary>
        ///   Raises the <see cref="Control.Paint" /> event.
        /// </summary>
        /// <remarks>
        ///   This paints the button to look split.
        /// </remarks>
        /// <param name="e">A <see cref="PaintEventArgs" /> describing the event arguments.</param>
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (!m_booShowSplit)
            {
                return;
            }

            var gphGraphics = pevent.Graphics;
            var rctBounds   = ClientRectangle;

            // draw the button background as according to the current state.
            if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
            {
                var backgroundBounds = rctBounds;
                backgroundBounds.Inflate(-1, -1);
                ButtonRenderer.DrawButton(gphGraphics, backgroundBounds, State);

                // button renderer doesnt draw the black frame when themes are off =(
                gphGraphics.DrawRectangle(SystemPens.WindowFrame, 0, 0, rctBounds.Width - 1, rctBounds.Height - 1);
            }
            else
            {
                ButtonRenderer.DrawButton(gphGraphics, rctBounds, State);
            }

            // calculate the current dropdown rectangle.
            m_rctDropDownRectangle = new Rectangle(rctBounds.Right - PUSH_BUTTON_WIDTH - 1, m_intBorderSize, PUSH_BUTTON_WIDTH,
                                                   rctBounds.Height - m_intBorderSize * 2);

            var intInternalBorder = m_intBorderSize;
            var rctFocusRect      = new Rectangle(intInternalBorder,
                                                  intInternalBorder,
                                                  rctBounds.Width - m_rctDropDownRectangle.Width - intInternalBorder,
                                                  rctBounds.Height - (intInternalBorder * 2));

            var booDrawSplitLine = (State == PushButtonState.Hot || State == PushButtonState.Pressed ||
                                    !Application.RenderWithVisualStyles);

            if (RightToLeft == RightToLeft.Yes)
            {
                m_rctDropDownRectangle.X = rctBounds.Left + 1;
                rctFocusRect.X           = m_rctDropDownRectangle.Right;
                if (booDrawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    gphGraphics.DrawLine(SystemPens.ButtonShadow, rctBounds.Left + PUSH_BUTTON_WIDTH, m_intBorderSize,
                                         rctBounds.Left + PUSH_BUTTON_WIDTH, rctBounds.Bottom - m_intBorderSize);
                    gphGraphics.DrawLine(SystemPens.ButtonFace, rctBounds.Left + PUSH_BUTTON_WIDTH + 1, m_intBorderSize,
                                         rctBounds.Left + PUSH_BUTTON_WIDTH + 1, rctBounds.Bottom - m_intBorderSize);
                }
            }
            else
            {
                if (booDrawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    gphGraphics.DrawLine(SystemPens.ButtonShadow, rctBounds.Right - PUSH_BUTTON_WIDTH, m_intBorderSize,
                                         rctBounds.Right - PUSH_BUTTON_WIDTH, rctBounds.Bottom - m_intBorderSize);
                    gphGraphics.DrawLine(SystemPens.ButtonFace, rctBounds.Right - PUSH_BUTTON_WIDTH - 1, m_intBorderSize,
                                         rctBounds.Right - PUSH_BUTTON_WIDTH - 1, rctBounds.Bottom - m_intBorderSize);
                }
            }

            // Draw an arrow in the correct location
            PaintArrow(gphGraphics, m_rctDropDownRectangle);

            // Figure out how to draw the text
            var tffFormatFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;

            // If we dont' use mnemonic, set formatFlag to NoPrefix as this will show ampersand.
            if (!UseMnemonic)
            {
                tffFormatFlags = tffFormatFlags | TextFormatFlags.NoPrefix;
            }
            else if (!ShowKeyboardCues)
            {
                tffFormatFlags = tffFormatFlags | TextFormatFlags.HidePrefix;
            }

            if (!string.IsNullOrEmpty(Text))
            {
                TextRenderer.DrawText(gphGraphics, Text, Font, rctFocusRect, SystemColors.ControlText, tffFormatFlags);
            }

            // draw the focus rectangle.
            if (State != PushButtonState.Pressed && Focused)
            {
                ControlPaint.DrawFocusRectangle(gphGraphics, rctFocusRect);
            }
        }
コード例 #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            // Clear background
            e.Graphics.Clear(SystemColors.Control);

            // Draw each part
            Point selection = (Point)this.anchorEdgeToXy[this.anchorEdge];

            double controlCenterX = (double)this.Width / 2.0;
            double controlCenterY = (double)this.Height / 2.0;

            Pen linePen            = new Pen(SystemColors.WindowText, (((float)Width + (float)Height) / 2.0f) / 64.0f);
            AdjustableArrowCap cap = new AdjustableArrowCap((float)Width / 32.0f, (float)Height / 32.0f, true);

            linePen.CustomEndCap = cap;

            Point mousePoint   = PointToClient(Control.MousePosition);
            int   mouseAnchorX = (int)Math.Floor(((float)mousePoint.X * 3.0f) / (float)this.Width);
            int   mouseAnchorY = (int)Math.Floor(((float)mousePoint.Y * 3.0f) / (float)this.Height);

            for (int y = 0; y < 3; ++y)
            {
                for (int x = 0; x < 3; ++x)
                {
                    AnchorEdge edge   = this.xyToAnchorEdge[y][x];
                    Point      offset = (Point)this.anchorEdgeToXy[edge];
                    Point      vector = new Point(offset.X - selection.X, offset.Y - selection.Y);

                    int left   = (this.Width * x) / 3;
                    int top    = (this.Height * y) / 3;
                    int right  = Math.Min(this.Width - 1, (this.Width * (x + 1)) / 3);
                    int bottom = Math.Min(this.Height - 1, (this.Height * (y + 1)) / 3);
                    int width  = right - left;
                    int height = bottom - top;

                    if (vector.X == 0 && vector.Y == 0)
                    {
                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(left, top, width, height), PushButtonState.Pressed);
                        e.Graphics.DrawImage(this.centerImage, left + 3, top + 3, width - 6, height - 6);
                    }
                    else
                    {
                        PushButtonState state;

                        if (drawHotPush && x == this.hotAnchorButton.X && y == this.hotAnchorButton.Y)
                        {
                            state = PushButtonState.Pressed;
                        }
                        else
                        {
                            state = PushButtonState.Normal;

                            if (!mouseDown && mouseAnchorX == x && mouseAnchorY == y)
                            {
                                state = PushButtonState.Hot;
                            }
                        }

                        ButtonRenderer.DrawButton(e.Graphics, new Rectangle(left, top, width, height), state);

                        if (vector.X <= 1 && vector.X >= -1 && vector.Y <= 1 && vector.Y >= -1)
                        {
                            double vectorMag = Math.Sqrt((double)((vector.X * vector.X) + (vector.Y * vector.Y)));
                            double normalX   = (double)vector.X / vectorMag;
                            double normalY   = (double)vector.Y / vectorMag;

                            Point center = new Point((left + right) / 2, (top + bottom) / 2);

                            Point start = new Point(center.X - (width / 4) * vector.X, center.Y - (height / 4) * vector.Y);
                            Point end   = new Point(
                                start.X + (int)(((double)width / 2.0) * normalX),
                                start.Y + (int)(((double)height / 2.0) * normalY));

                            PixelOffsetMode oldPOM = e.Graphics.PixelOffsetMode;
                            e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
                            e.Graphics.DrawLine(linePen, start, end);
                            e.Graphics.PixelOffsetMode = oldPOM;
                        }
                    }
                }
            }

            linePen.Dispose();
            base.OnPaint(e);
        }
コード例 #14
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (!showSplit)
            {
                return;
            }

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = ClientRectangle;

            // draw the button background as according to the current state.
            if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
            {
                Rectangle backgroundBounds = bounds;
                backgroundBounds.Inflate(-1, -1);
                ButtonRenderer.DrawButton(g, backgroundBounds, State);

                // button renderer doesnt draw the black frame when themes are off
                g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);
            }
            else
            {
                ButtonRenderer.DrawButton(g, bounds, State);
            }

            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - SplitSectionWidth, 0, SplitSectionWidth, bounds.Height);

            int       internalBorder = BorderSize;
            Rectangle focusRect      =
                new Rectangle(internalBorder - 1,
                              internalBorder - 1,
                              bounds.Width - dropDownRectangle.Width - internalBorder,
                              bounds.Height - (internalBorder * 2) + 2);

            bool drawSplitLine = ((showSplit && ShowSplitlineAlways) || State == PushButtonState.Hot || State == PushButtonState.Pressed || !Application.RenderWithVisualStyles);


            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X = bounds.Left + 1;
                focusRect.X         = dropDownRectangle.Right;

                if (drawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Left + SplitSectionWidth, BorderSize, bounds.Left + SplitSectionWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Left + SplitSectionWidth + 1, BorderSize, bounds.Left + SplitSectionWidth + 1, bounds.Bottom - BorderSize);
                }
            }
            else
            {
                if (drawSplitLine)
                {
                    // draw two lines at the edge of the dropdown button
                    g.DrawLine(SystemPens.ButtonShadow, bounds.Right - SplitSectionWidth, BorderSize, bounds.Right - SplitSectionWidth, bounds.Bottom - BorderSize);
                    g.DrawLine(SystemPens.ButtonFace, bounds.Right - SplitSectionWidth - 1, BorderSize, bounds.Right - SplitSectionWidth - 1, bounds.Bottom - BorderSize);
                }
            }

            // Draw an arrow in the correct location
            PaintArrow(g, dropDownRectangle);

            //paint the image and text in the "button" part of the splitButton
            PaintTextandImage(g, new Rectangle(0, 0, ClientRectangle.Width - SplitSectionWidth, ClientRectangle.Height));

            // draw the focus rectangle.
            if (State != PushButtonState.Pressed && Focused && ShowFocusCues)
            {
                ControlPaint.DrawFocusRectangle(g, focusRect);
            }
        }
コード例 #15
0
        /// <summary>
        /// Paints the split button.
        /// </summary>
        /// <param name="pevent"></param>
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            Graphics  g      = pevent.Graphics;
            Rectangle bounds = this.ClientRectangle;

            // draw the button background as according to the current state.
            if (State != PushButtonState.Pressed && IsDefault && !Application.RenderWithVisualStyles)
            {
                Rectangle backgroundBounds = bounds;
                backgroundBounds.Inflate(-1, -1);
                ButtonRenderer.DrawButton(g, backgroundBounds, State);

                // button renderer doesnt draw the black frame when themes are off =(
                g.DrawRectangle(SystemPens.WindowFrame, 0, 0, bounds.Width - 1, bounds.Height - 1);
            }
            else
            {
                ButtonRenderer.DrawButton(g, bounds, State);
            }

            // calculate the current dropdown rectangle.
            dropDownRectangle = new Rectangle(bounds.Right - PushButtonWidth - 1, BorderSize, PushButtonWidth, bounds.Height - BorderSize * 2);

            int       internalBorder = BorderSize;
            Rectangle focusRect      = new Rectangle(internalBorder, internalBorder, bounds.Width - dropDownRectangle.Width - internalBorder, bounds.Height - (internalBorder * 2));

            bool drawSplitLine = (State == PushButtonState.Hot || State == PushButtonState.Pressed || !Application.RenderWithVisualStyles);

            Point topLeftLinePosition     = new Point();
            Point bottomRightLinePosition = new Point();

            if (RightToLeft == RightToLeft.Yes)
            {
                dropDownRectangle.X       = bounds.Left + 1;
                focusRect.X               = dropDownRectangle.Right;
                topLeftLinePosition.X     = bounds.Left + PushButtonWidth;
                topLeftLinePosition.Y     = BorderSize;
                bottomRightLinePosition.X = bounds.Left + PushButtonWidth;
                bottomRightLinePosition.Y = bounds.Bottom - BorderSize;
            }
            else
            {
                topLeftLinePosition.X     = bounds.Right - PushButtonWidth;
                topLeftLinePosition.Y     = BorderSize;
                bottomRightLinePosition.X = bounds.Right - PushButtonWidth;
                bottomRightLinePosition.Y = bounds.Bottom - BorderSize;
            }

            if (drawSplitLine)
            {
                Border3DStyle style = Border3DStyle.RaisedInner;
                ControlPaint.DrawBorder3D(g, topLeftLinePosition.X, topLeftLinePosition.Y, 0, bottomRightLinePosition.Y - topLeftLinePosition.Y, style);
            }
            // Draw an arrow in the correct location
            PaintArrow(g, dropDownRectangle);

            TextFormatFlags formatFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter;

            if (!UseMnemonic)
            {
                formatFlags = formatFlags | TextFormatFlags.NoPrefix;
            }
            else if (!ShowKeyboardCues)
            {
                formatFlags = formatFlags | TextFormatFlags.HidePrefix;
            }

            if (!string.IsNullOrEmpty(this.Text))
            {
                TextRenderer.DrawText(g, Text, Font, focusRect, SystemColors.ControlText, formatFlags);
            }
        }
コード例 #16
0
                protected override void OnPaint(PaintEventArgs e)
                {
                    Graphics g = e.Graphics;

                    if (_ellipsis)
                    {
                        PushButtonState buttonState = PushButtonState.Normal;
                        if (_mouseDown)
                        {
                            buttonState = PushButtonState.Pressed;
                        }
                        else if (_mouseOver)
                        {
                            buttonState = PushButtonState.Hot;
                        }

                        ButtonRenderer.DrawButton(g, new Rectangle(-1, -1, Width + 2, Height + 2), "…", Font, Focused, buttonState);
                    }
                    else
                    {
                        if (ComboBoxRenderer.IsSupported)
                        {
                            ComboBoxState state = ComboBoxState.Normal;
                            if (Enabled)
                            {
                                if (_mouseDown)
                                {
                                    state = ComboBoxState.Pressed;
                                }
                                else if (_mouseOver)
                                {
                                    state = ComboBoxState.Hot;
                                }
                            }
                            else
                            {
                                state = ComboBoxState.Disabled;
                            }

                            ComboBoxRenderer.DrawDropDownButton(g, new Rectangle(0, 0, Width, Height), state);
                        }
                        else
                        {
                            PushButtonState buttonState = PushButtonState.Normal;
                            if (Enabled)
                            {
                                if (_mouseDown)
                                {
                                    buttonState = PushButtonState.Pressed;
                                }
                                else if (_mouseOver)
                                {
                                    buttonState = PushButtonState.Hot;
                                }
                            }
                            else
                            {
                                buttonState = PushButtonState.Disabled;
                            }

                            ButtonRenderer.DrawButton(g, new Rectangle(-1, -1, Width + 2, Height + 2), string.Empty, Font, Focused, buttonState);
                            // Draw the arrow icon
                            try
                            {
                                Icon icon = new Icon(typeof(DesignerActionPanel), "Arrow.ico");
                                try
                                {
                                    Bitmap arrowBitmap = icon.ToBitmap();

                                    // Make sure we draw properly under high contrast by re-mapping
                                    // the arrow color to the WindowText color
                                    ImageAttributes attrs = new ImageAttributes();
                                    try
                                    {
                                        ColorMap cm = new ColorMap
                                        {
                                            OldColor = Color.Black,
                                            NewColor = SystemColors.WindowText
                                        };
                                        attrs.SetRemapTable(new ColorMap[] { cm }, ColorAdjustType.Bitmap);
                                        int imageWidth  = arrowBitmap.Width;
                                        int imageHeight = arrowBitmap.Height;
                                        g.DrawImage(arrowBitmap, new Rectangle((Width - imageWidth + 1) / 2, (Height - imageHeight + 1) / 2, imageWidth, imageHeight),
                                                    0, 0, imageWidth, imageWidth, GraphicsUnit.Pixel, attrs, null, IntPtr.Zero);
                                    }
                                    finally
                                    {
                                        if (attrs != null)
                                        {
                                            attrs.Dispose();
                                        }
                                    }
                                }
                                finally
                                {
                                    if (icon != null)
                                    {
                                        icon.Dispose();
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }

                        if (Focused)
                        {
                            ControlPaint.DrawFocusRectangle(g, new Rectangle(2, 2, Width - 5, Height - 5));
                        }
                    }
                }
コード例 #17
0
        private void OnGdipPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.Clear(this.BackColor);
            Point  point = this.anchorEdgeToXy[this.anchorEdge];
            double num   = ((double)base.Width) / 2.0;
            double num2  = ((double)base.Height) / 2.0;

            using (Pen pen = new Pen(SystemColors.WindowText, ((base.Width + base.Height) / 2f) / 64f))
            {
                AdjustableArrowCap cap = new AdjustableArrowCap(((float)base.Width) / 32f, ((float)base.Height) / 32f, true);
                pen.CustomEndCap = cap;
                Point point2 = base.PointToClient(Control.MousePosition);
                int   num3   = (int)Math.Floor((double)((point2.X * 3f) / ((float)base.Width)));
                int   num4   = (int)Math.Floor((double)((point2.Y * 3f) / ((float)base.Height)));
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        PaintDotNet.AnchorEdge edge = this.xyToAnchorEdge[i][j];
                        Point point3 = this.anchorEdgeToXy[edge];
                        Point point4 = new Point(point3.X - point.X, point3.Y - point.Y);
                        int   x      = (base.Width * j) / 3;
                        int   y      = (base.Height * i) / 3;
                        int   num9   = Math.Min((int)(base.Width - 1), (int)((base.Width * (j + 1)) / 3));
                        int   num10  = Math.Min((int)(base.Height - 1), (int)((base.Height * (i + 1)) / 3));
                        int   width  = num9 - x;
                        int   height = num10 - y;
                        if ((point4.X == 0) && (point4.Y == 0))
                        {
                            ButtonRenderer.DrawButton(e.Graphics, new Rectangle(x, y, width, height), PushButtonState.Pressed);
                            e.Graphics.DrawImage(this.centerImage, (int)(x + 3), (int)(y + 3), (int)(width - 6), (int)(height - 6));
                        }
                        else
                        {
                            PushButtonState pressed;
                            if ((this.drawHotPush && (j == this.hotAnchorButton.X)) && (i == this.hotAnchorButton.Y))
                            {
                                pressed = PushButtonState.Pressed;
                            }
                            else
                            {
                                pressed = PushButtonState.Normal;
                                if ((!this.mouseDown && (num3 == j)) && (num4 == i))
                                {
                                    pressed = PushButtonState.Hot;
                                }
                            }
                            ButtonRenderer.DrawButton(e.Graphics, new Rectangle(x, y, width, height), pressed);
                            if (((point4.X <= 1) && (point4.X >= -1)) && ((point4.Y <= 1) && (point4.Y >= -1)))
                            {
                                double          num13           = Math.Sqrt((double)((point4.X * point4.X) + (point4.Y * point4.Y)));
                                double          num14           = ((double)point4.X) / num13;
                                double          num15           = ((double)point4.Y) / num13;
                                Point           point5          = new Point((x + num9) / 2, (y + num10) / 2);
                                Point           point6          = new Point(point5.X - ((width / 4) * point4.X), point5.Y - ((height / 4) * point4.Y));
                                Point           point7          = new Point(point6.X + ((int)((((double)width) / 2.0) * num14)), point6.Y + ((int)((((double)height) / 2.0) * num15)));
                                PixelOffsetMode pixelOffsetMode = e.Graphics.PixelOffsetMode;
                                e.Graphics.PixelOffsetMode = PixelOffsetMode.Half;
                                e.Graphics.DrawLine(pen, point6, point7);
                                e.Graphics.PixelOffsetMode = pixelOffsetMode;
                            }
                        }
                    }
                }
            }
            base.OnPaint(e);
        }
コード例 #18
0
        //*
        //     * Creates a List of printed page images
        //     * both for use in the preview form and for printing
        //
        public List <Bitmap> getPages(DataGridView mainTable, bool includeRowHeaders, bool includeColumnHeaders, bool includeHiddenColumns, bool portrait)
        {
            mainTable.EndEdit();

            List <Bitmap> pageImages = new List <Bitmap>();

            int startColumn = 0;
            int startRow    = 0;
            int lastColumn  = -1;
            int lastRow     = -1;

            Font ulFont = new Font(mainTable.Font, mainTable.Font.Style | FontStyle.Underline);

            while (true)
            {
                //612, 792
                double    sumX         = (includeRowHeaders ? mainTable.RowHeadersWidth : 0);
                List <xC> xCoordinates = new List <xC>();

                for (int x = startColumn; x <= mainTable.ColumnCount - 1; x++)
                {
                    if (!mainTable.Columns[x].Visible & !includeHiddenColumns)
                    {
                        xCoordinates.Add(new xC(0, 0));
                        continue;
                    }
                    if ((sumX + mainTable.Columns[x].Width) < (portrait ? 765 : 1060))
                    {
                        xCoordinates.Add(new xC(Convert.ToInt32(sumX), mainTable.Columns[x].Width));
                        sumX += mainTable.Columns[x].Width;
                        if (x == mainTable.ColumnCount - 1)
                        {
                            lastColumn = x;
                        }
                    }
                    else
                    {
                        lastColumn = x - 1;
                        break;                         // TODO: might not be correct. Was : Exit For
                    }
                }

                double    sumY         = (includeColumnHeaders ? mainTable.ColumnHeadersHeight : 0);
                List <yC> yCoordinates = new List <yC>();

                for (int y = startRow; y <= mainTable.RowCount - 1; y++)
                {
                    if ((sumY + mainTable.Rows[y].Height) < (portrait ? 1015 : 765))
                    {
                        yCoordinates.Add(new yC(Convert.ToInt32(sumY), mainTable.Rows[y].Height));
                        sumY += mainTable.Rows[y].Height;
                        if (y == mainTable.RowCount - 1)
                        {
                            lastRow = y;
                        }
                    }
                    else
                    {
                        lastRow = y - 1;
                        break;
                    }
                }

                Bitmap img = null;
                if (portrait)
                {
                    img = new Bitmap(850, 1100);
                }
                else
                {
                    img = new Bitmap(1100, 850);
                }
                Graphics g = Graphics.FromImage(img);

                g.Clear(Color.White);
                g.TranslateTransform(20, 20);

                // get metrics from the graphics
                //Dim metrics As SizeF = g2d.getFontMetrics(mainTable.getFont())
                //Dim height As Integer = metrics.getHeight()
                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Near;
                sf.LineAlignment = StringAlignment.Center;

                SolidBrush brush = new SolidBrush(mainTable.ColumnHeadersDefaultCellStyle.BackColor);

                if (includeColumnHeaders)
                {
                    for (int x = startColumn; x <= lastColumn; x++)
                    {
                        if (!mainTable.Columns[x].Visible & !includeHiddenColumns)
                        {
                            continue;
                        }
                        Rectangle r = new Rectangle(xCoordinates[x - startColumn].X, 0, xCoordinates[x - startColumn].Width, mainTable.ColumnHeadersHeight);
                        g.FillRectangle(brush, r);
                        g.DrawRectangle(Pens.DarkGray, r);

                        bool b = false;
                        if (mainTable.Columns[x].HeaderCell is checkAllHeaderCell || mainTable.Columns[x].HeaderCell is checkHideColumnHeaderCell)
                        {
                            if (mainTable.Columns[x].HeaderCell is checkAllHeaderCell)
                            {
                                checkAllHeaderCell hc = (checkAllHeaderCell)mainTable.Columns[x].HeaderCell;
                                b = hc.isChecked;
                            }
                            else if (mainTable.Columns[x].HeaderCell is checkHideColumnHeaderCell)
                            {
                                checkHideColumnHeaderCell hc = (checkHideColumnHeaderCell)mainTable.Columns[x].HeaderCell;
                                b = hc.isChecked;
                            }
                            Point l = new Point(r.Width - 18, 5);
                            CheckBoxRenderer.DrawCheckBox(g, new Point(r.X + l.X, l.Y), b ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                        }

                        r.Inflate(-2, -2);
                        g.DrawString(mainTable.Columns[x].HeaderText, mainTable.Font, Brushes.Black, r, sf);
                    }
                }

                if (includeRowHeaders)
                {
                    for (int y = startRow - 1; y <= lastRow; y++)
                    {
                        if (y == startRow - 1)
                        {
                            Rectangle r = new Rectangle(0, 0, mainTable.RowHeadersWidth, mainTable.ColumnHeadersHeight);
                            g.FillRectangle(brush, r);
                            g.DrawRectangle(Pens.DarkGray, r);
                        }
                        else
                        {
                            Rectangle r = new Rectangle(0, yCoordinates[y - startRow].Y, mainTable.RowHeadersWidth, yCoordinates[y - startRow].Height);
                            g.FillRectangle(brush, r);
                            g.DrawRectangle(Pens.DarkGray, r);
                            r.Inflate(-2, -2);
                            object o = mainTable.Rows[y].HeaderCell.Value;
                            g.DrawString(o != null ? o.ToString() : "", mainTable.Font, Brushes.Black, r, sf);
                        }
                    }
                }

                for (int x = startColumn; x <= lastColumn; x++)
                {
                    if (!mainTable.Columns[x].Visible & !includeHiddenColumns)
                    {
                        continue;
                    }
                    for (int y = startRow; y <= lastRow; y++)
                    {
                        Rectangle r  = new Rectangle(xCoordinates[x - startColumn].X, yCoordinates[y - startRow].Y, xCoordinates[x - startColumn].Width, yCoordinates[y - startRow].Height);
                        Rectangle r2 = new Rectangle(r.Left, r.Top, r.Width, r.Height);
                        r2.Inflate(-2, -2);

                        //DataGridViewButtonColumn
                        //DataGridViewCheckBoxColumn
                        //DataGridViewComboBoxColumn
                        //DataGridViewImageColumn
                        //DataGridViewLinkColumn
                        //DataGridViewTextBoxColumn
                        if (mainTable[x, y] is DataGridViewTextBoxCell)
                        {
                            if (!mainTable[x, y].Style.BackColor.Equals(Color.Empty))
                            {
                                g.FillRectangle(new SolidBrush(mainTable[x, y].Style.BackColor), r);
                            }
                            else
                            {
                                if (!mainTable[x, y].OwningColumn.DefaultCellStyle.BackColor.Equals(Color.Empty))
                                {
                                    g.FillRectangle(new SolidBrush(mainTable[x, y].OwningColumn.DefaultCellStyle.BackColor), r);
                                }
                                if (!mainTable[x, y].OwningRow.DefaultCellStyle.BackColor.Equals(Color.Empty))
                                {
                                    g.FillRectangle(new SolidBrush(mainTable[x, y].OwningRow.DefaultCellStyle.BackColor), r);
                                }
                                if (!mainTable.AlternatingRowsDefaultCellStyle.BackColor.Equals(Color.Empty) && y % 2 == 1)
                                {
                                    g.FillRectangle(new SolidBrush(mainTable.AlternatingRowsDefaultCellStyle.BackColor), r);
                                }
                            }

                            string cellValue = "";
                            if (mainTable[x, y].Value != null)
                            {
                                cellValue = mainTable[x, y].Value.ToString();
                                g.DrawString(cellValue, mainTable.Font, Brushes.Black, r2, sf);
                            }
                        }
                        else if (mainTable[x, y] is DataGridViewLinkCell)
                        {
                            if (!mainTable[x, y].Style.BackColor.Equals(Color.Empty))
                            {
                                g.FillRectangle(new SolidBrush(mainTable[x, y].Style.BackColor), r);
                            }
                            else
                            {
                                if (!mainTable[x, y].OwningColumn.DefaultCellStyle.BackColor.Equals(Color.Empty))
                                {
                                    g.FillRectangle(new SolidBrush(mainTable[x, y].OwningColumn.DefaultCellStyle.BackColor), r);
                                }
                                if (!mainTable[x, y].OwningRow.DefaultCellStyle.BackColor.Equals(Color.Empty))
                                {
                                    g.FillRectangle(new SolidBrush(mainTable[x, y].OwningRow.DefaultCellStyle.BackColor), r);
                                }
                                if (!mainTable.AlternatingRowsDefaultCellStyle.BackColor.Equals(Color.Empty) && y % 2 == 1)
                                {
                                    g.FillRectangle(new SolidBrush(mainTable.AlternatingRowsDefaultCellStyle.BackColor), r);
                                }
                            }

                            string cellValue = "";
                            if (mainTable[x, y].Value != null)
                            {
                                cellValue = mainTable[x, y].Value.ToString();
                                Color c = ((DataGridViewLinkCell)mainTable[x, y]).LinkVisited ? Color.Purple : Color.Blue;
                                g.DrawString(cellValue, ulFont, new SolidBrush(c), r2, sf);
                            }
                        }
                        else if (mainTable[x, y] is DataGridViewComboBoxCell)
                        {
                            ComboBoxRenderer.DrawDropDownButton(g, new Rectangle(r.X + r.Width - 16, r.Top, 16, r.Height), System.Windows.Forms.VisualStyles.ComboBoxState.Normal);
                            string cellValue = "";
                            if (mainTable[x, y].Value != null)
                            {
                                cellValue = mainTable[x, y].Value.ToString();
                                g.DrawString(cellValue, mainTable.Font, Brushes.Black, r2, sf);
                            }
                        }
                        else if (mainTable[x, y] is DataGridViewCheckBoxCell)
                        {
                            if (!mainTable[x, y].Style.BackColor.Equals(Color.Empty))
                            {
                                g.FillRectangle(new SolidBrush(mainTable[x, y].Style.BackColor), r);
                            }
                            else
                            {
                                if (!mainTable[x, y].OwningColumn.DefaultCellStyle.BackColor.Equals(Color.Empty))
                                {
                                    g.FillRectangle(new SolidBrush(mainTable[x, y].OwningColumn.DefaultCellStyle.BackColor), r);
                                }
                                if (!mainTable[x, y].OwningRow.DefaultCellStyle.BackColor.Equals(Color.Empty))
                                {
                                    g.FillRectangle(new SolidBrush(mainTable[x, y].OwningRow.DefaultCellStyle.BackColor), r);
                                }
                                if (!mainTable.AlternatingRowsDefaultCellStyle.BackColor.Equals(Color.Empty) && y % 2 == 1)
                                {
                                    g.FillRectangle(new SolidBrush(mainTable.AlternatingRowsDefaultCellStyle.BackColor), r);
                                }
                            }

                            bool b = false;
                            if (bool.TryParse(mainTable[x, y].FormattedValue.ToString(), out b) && b)
                            {
                                CheckBoxRenderer.DrawCheckBox(g, new Point(r.Left + Convert.ToInt32((r.Width - 12) / 2), r.Top + Convert.ToInt32((r.Height - 12) / 2)), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);
                            }
                            else
                            {
                                CheckBoxRenderer.DrawCheckBox(g, new Point(r.Left + Convert.ToInt32((r.Width - 12) / 2), r.Top + Convert.ToInt32((r.Height - 12) / 2)), System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
                            }
                        }
                        else if (mainTable[x, y] is DataGridViewButtonCell)
                        {
                            ButtonRenderer.DrawButton(g, r2, System.Windows.Forms.VisualStyles.PushButtonState.Normal);
                            sf.Alignment = StringAlignment.Center;
                            object o = mainTable[x, y].Value;
                            if (o != null)
                            {
                                g.DrawString(o.ToString(), mainTable.Font, Brushes.Black, r2, sf);
                            }
                        }
                        else if (mainTable[x, y] is DataGridViewImageCell)
                        {
                            if (y != mainTable.NewRowIndex)
                            {
                                if ((mainTable[x, y].Value != null))
                                {
                                    g.DrawImage((Bitmap)mainTable[x, y].FormattedValue, r);
                                }
                            }
                        }
                        g.DrawRectangle(Pens.DarkGray, r);
                    }
                }

                String footer    = "Page " + (pageImages.Count() + 1).ToString();
                int    textWidth = TextRenderer.MeasureText(footer, mainTable.Font).Width;
                g.DrawString(footer, mainTable.Font, Brushes.Black, Convert.ToSingle((img.Width - textWidth) / 2) - 20, Convert.ToSingle(img.Height - 85));

                pageImages.Add(img);

                if (lastColumn < mainTable.ColumnCount - 1)
                {
                    startColumn = lastColumn + 1;
                }
                else
                {
                    if (lastRow < mainTable.RowCount - 1)
                    {
                        startColumn = 0;
                        startRow    = lastRow + 1;
                    }
                    else
                    {
                        break;                         // TODO: might not be correct. Was : Exit While
                    }
                }
            }

            return(pageImages);
        }
コード例 #19
0
        /// <summary>
        /// Paints the column header cell, including the drop-down button.
        /// </summary>
        /// <param name="graphics">The Graphics used to paint the DataGridViewCell.</param>
        /// <param name="clipBounds">A Rectangle that represents the area of the DataGridView that needs to be repainted.</param>
        /// <param name="cellBounds">A Rectangle that contains the bounds of the DataGridViewCell that is being painted.</param>
        /// <param name="rowIndex">The row index of the cell that is being painted.</param>
        /// <param name="cellState">A bitwise combination of DataGridViewElementStates values that specifies the state of the cell.</param>
        /// <param name="value">The data of the DataGridViewCell that is being painted.</param>
        /// <param name="formattedValue">The formatted data of the DataGridViewCell that is being painted.</param>
        /// <param name="errorText">An error message that is associated with the cell.</param>
        /// <param name="cellStyle">A DataGridViewCellStyle that contains formatting and style information about the cell.</param>
        /// <param name="advancedBorderStyle">A DataGridViewAdvancedBorderStyle that contains border styles for the cell that is being painted.</param>
        /// <param name="paintParts">A bitwise combination of the DataGridViewPaintParts values that specifies which parts of the cell need to be painted.</param>
        protected override void Paint(System.Drawing.Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            // Continue only if the drop down is to be visible and ContentBackground is part of the paint request.
            if (!this.IsProgrammaticSorting || (paintParts & DataGridViewPaintParts.ContentBackground) == 0)
            {
                return;
            }

            Rectangle buttonBounds = this.DropDownButtonBounds;

            if (buttonBounds.Width > 0 && buttonBounds.Height > 0)             // make sure there's something to draw...
            {
                // Paint the button manually or using visual styles if visual styles
                // are enabled, using the correct state depending on whether the
                // filter list is showing and whether there is a filter in effect
                // for the current column.
                if (Application.RenderWithVisualStyles)
                {
                    ComboBoxState state = ComboBoxState.Normal;
                    if (!this.DropDownEnabled)
                    {
                        state = ComboBoxState.Disabled;
                    }
                    else if (this.IsDropDownShowing)
                    {
                        state = ComboBoxState.Pressed;
                    }
                    ComboBoxRenderer.DrawDropDownButton(graphics, buttonBounds, state);
                }
                else
                {
                    int             pressedOffset = 0;
                    PushButtonState state         = PushButtonState.Normal;
                    if (!this.DropDownEnabled)
                    {
                        state = PushButtonState.Disabled;
                    }
                    else if (this.IsDropDownShowing)
                    {
                        state         = PushButtonState.Pressed;
                        pressedOffset = 1;
                    }
                    ButtonRenderer.DrawButton(graphics, buttonBounds, state);
                    graphics.FillPolygon(this.DropDownEnabled ? SystemBrushes.ControlText : SystemBrushes.InactiveCaption,
                                         new Point[]
                    {
                        new Point(
                            buttonBounds.Width / 2 +
                            buttonBounds.Left - 1 + pressedOffset,
                            buttonBounds.Height * 3 / 4 +
                            buttonBounds.Top - 1 + pressedOffset),
                        new Point(
                            buttonBounds.Width / 4 +
                            buttonBounds.Left + pressedOffset,
                            buttonBounds.Height / 2 +
                            buttonBounds.Top - 1 + pressedOffset),
                        new Point(
                            buttonBounds.Width * 3 / 4 +
                            buttonBounds.Left - 1 + pressedOffset,
                            buttonBounds.Height / 2 +
                            buttonBounds.Top - 1 + pressedOffset)
                    });
                }

                // and then paint a filtering and/or sorting glyph
                if (_filtered)
                {
                    Bitmap    glyph = Properties.Resources.FilterHeaderCellGlyph;
                    Rectangle cbb   = this.DataGridView.GetCellDisplayRectangle(this.ColumnIndex, -1, false);
                    graphics.DrawImage(glyph, new Rectangle(buttonBounds.Left - glyph.Width - 3, (cbb.Height - glyph.Height) / 2, glyph.Width, glyph.Height));
                }
            }
        }