public void DrawFunction(DrawableFunction drawableFunction) { drawer.Clear(drawer.GetNearestColor(defaultColor)); foreach (var drawableRactangle in drawableFunction.GetDrawableRactangles()) { DrawRactangle(drawableRactangle, drawableFunction.GetheightColorGetter().GetColorByHeight(drawableRactangle.AverageZ)); } }
private static Color GetAlphaBlendedColor(Graphics g, Color src, Color dest, int alpha) { int red = ((src.R * alpha) + ((0xff - alpha) * dest.R)) / 0xff; int green = ((src.G * alpha) + ((0xff - alpha) * dest.G)) / 0xff; int blue = ((src.B * alpha) + ((0xff - alpha) * dest.B)) / 0xff; int num4 = ((src.A * alpha) + ((0xff - alpha) * dest.A)) / 0xff; if (g == null) { return Color.FromArgb(num4, red, green, blue); } return g.GetNearestColor(Color.FromArgb(num4, red, green, blue)); }
private static Color GetAlphaBlendedColorHighRes(Graphics graphics, Color src, Color dest, int alpha) { int num; int num2; int num6 = alpha; if (num6 < 100) { num2 = 100 - num6; num = 100; } else { num2 = 0x3e8 - num6; num = 0x3e8; } int red = (((num6 * src.R) + (num2 * dest.R)) + (num / 2)) / num; int green = (((num6 * src.G) + (num2 * dest.G)) + (num / 2)) / num; int blue = (((num6 * src.B) + (num2 * dest.B)) + (num / 2)) / num; if (graphics == null) { return Color.FromArgb(red, green, blue); } return graphics.GetNearestColor(Color.FromArgb(red, green, blue)); }
public virtual Brush GetLineBrush(Graphics g) { if (ownerGrid.lineBrush == null) { Color clr = g.GetNearestColor(ownerGrid.LineColor); ownerGrid.lineBrush = new SolidBrush(clr); } return ownerGrid.lineBrush; }
public virtual void PaintLabel(Graphics g, Rectangle rect, Rectangle clipRect, bool selected, bool paintFullLabel) { PropertyGridView gridEntryHost = this.GridEntryHost; string propertyLabel = this.PropertyLabel; int width = gridEntryHost.GetOutlineIconSize() + 5; Brush brush = selected ? SystemBrushes.Highlight : this.GetBackgroundBrush(g); if (selected && !this.hasFocus) { brush = gridEntryHost.GetLineBrush(g); } bool boldFont = (this.Flags & 0x40) != 0; Font f = this.GetFont(boldFont); int num2 = this.GetLabelTextWidth(propertyLabel, g, f); int num3 = paintFullLabel ? num2 : 0; int x = rect.X + this.PropertyLabelIndent; Brush brush2 = brush; if (paintFullLabel && (num3 >= (rect.Width - (x + 2)))) { int num5 = (x + num3) + 2; g.FillRectangle(brush2, width - 1, rect.Y, (num5 - width) + 3, rect.Height); Pen pen = new Pen(gridEntryHost.GetLineColor()); g.DrawLine(pen, num5, rect.Y, num5, rect.Height); pen.Dispose(); rect.Width = num5 - rect.X; } else { g.FillRectangle(brush2, rect.X, rect.Y, rect.Width, rect.Height); } Brush lineBrush = gridEntryHost.GetLineBrush(g); g.FillRectangle(lineBrush, rect.X, rect.Y, width, rect.Height); if (selected && this.hasFocus) { g.FillRectangle(SystemBrushes.Highlight, x, rect.Y, (rect.Width - x) - 1, rect.Height); } int num6 = Math.Min((int) ((rect.Width - x) - 1), (int) (num2 + 2)); Rectangle a = new Rectangle(x, rect.Y + 1, num6, rect.Height - 1); if (Rectangle.Intersect(a, clipRect).IsEmpty) { goto Label_0292; } Region clip = g.Clip; g.SetClip(a); Color color = (selected && this.hasFocus) ? SystemColors.HighlightText : g.GetNearestColor(this.LabelTextColor); if (this.ownerGrid.UseCompatibleTextRendering) { using (Brush brush4 = new SolidBrush(color)) { StringFormat format = new StringFormat(StringFormatFlags.NoWrap) { Trimming = StringTrimming.None }; g.DrawString(propertyLabel, f, brush4, a, format); goto Label_0257; } } TextRenderer.DrawText(g, propertyLabel, f, a, color, PropertyGrid.MeasureTextHelper.GetTextRendererFlags()); Label_0257: g.SetClip(clip, CombineMode.Replace); clip.Dispose(); if (num6 <= num2) { this.labelTipPoint = new Point(x + 2, rect.Y + 1); } else { this.labelTipPoint = InvalidPoint; } Label_0292: rect.Y--; rect.Height += 2; this.PaintOutline(g, rect); }
public virtual Brush GetLineBrush(Graphics g) { if (this.ownerGrid.lineBrush == null) { System.Drawing.Color nearestColor = g.GetNearestColor(this.ownerGrid.LineColor); this.ownerGrid.lineBrush = new SolidBrush(nearestColor); } return this.ownerGrid.lineBrush; }
// PaintPrivate is used in three places that need to duplicate the paint code: // 1. DataGridViewCell::Paint method // 2. DataGridViewCell::GetContentBounds // 3. DataGridViewCell::GetErrorIconBounds // // if computeContentBounds is true then PaintPrivate returns the contentBounds // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds // else it returns Rectangle.Empty; private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { // Parameter checking. // One bit and one bit only should be turned on Debug.Assert(paint || computeContentBounds || computeErrorIconBounds); Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint); Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds); Debug.Assert(cellStyle != null); Rectangle resultBounds; if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle valBounds = cellBounds; Rectangle borderWidths = BorderWidths(advancedBorderStyle); valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; bool cellSelected = (elementState & DataGridViewElementStates.Selected) != 0; bool drawAsMixedCheckBox = false, drawErrorText = true; CheckState checkState; ButtonState bs; Point ptCurrentCell = this.DataGridView.CurrentCellAddress; if (ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex && this.DataGridView.IsCurrentCellInEditMode) { drawErrorText = false; } if (formattedValue != null && formattedValue is CheckState) { checkState = (CheckState)formattedValue; bs = (checkState == CheckState.Unchecked) ? ButtonState.Normal : ButtonState.Checked; drawAsMixedCheckBox = (checkState == CheckState.Indeterminate); } else if (formattedValue != null && formattedValue is bool) { if ((bool)formattedValue) { checkState = CheckState.Checked; bs = ButtonState.Checked; } else { checkState = CheckState.Unchecked; bs = ButtonState.Normal; } } else { // The provided formatted value has a wrong type. We raised a DataError event while formatting. bs = ButtonState.Normal; // Default rendering of the checkbox with wrong formatted value type. checkState = CheckState.Unchecked; } if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0) { bs |= ButtonState.Pushed; } SolidBrush br = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { g.FillRectangle(br, valBounds); } if (cellStyle.Padding != Padding.Empty) { if (this.DataGridView.RightToLeftInternal) { valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } valBounds.Width -= cellStyle.Padding.Horizontal; valBounds.Height -= cellStyle.Padding.Vertical; } if (paint && DataGridViewCell.PaintFocus(paintParts) && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex) { // Draw focus rectangle ControlPaint.DrawFocusRectangle(g, valBounds, Color.Empty, br.Color); } Rectangle errorBounds = valBounds; valBounds.Inflate(-DATAGRIDVIEWCHECKBOXCELL_margin, -DATAGRIDVIEWCHECKBOXCELL_margin); Size checkBoxSize; CheckBoxState themeCheckBoxState = CheckBoxState.UncheckedNormal; if (this.DataGridView.ApplyVisualStylesToInnerCells) { themeCheckBoxState = CheckBoxRenderer.ConvertFromButtonState(bs, drawAsMixedCheckBox, this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInContentBounds); checkBoxSize = CheckBoxRenderer.GetGlyphSize(g, themeCheckBoxState); switch (this.FlatStyle) { case FlatStyle.Standard: case FlatStyle.System: break; case FlatStyle.Flat: checkBoxSize.Width -= 3; checkBoxSize.Height -= 3; break; case FlatStyle.Popup: checkBoxSize.Width -= 2; checkBoxSize.Height -= 2; break; } } else { switch (this.FlatStyle) { case FlatStyle.Flat: checkBoxSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal); checkBoxSize.Width -= 3; checkBoxSize.Height -= 3; break; case FlatStyle.Popup: checkBoxSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal); checkBoxSize.Width -= 2; checkBoxSize.Height -= 2; break; default: // FlatStyle.Standard || FlatStyle.System checkBoxSize = new Size(SystemInformation.Border3DSize.Width * 2 + 9, SystemInformation.Border3DSize.Width * 2 + 9); break; } } if (valBounds.Width >= checkBoxSize.Width && valBounds.Height >= checkBoxSize.Height && (paint || computeContentBounds)) { int checkBoxX = 0, checkBoxY = 0; if ((!this.DataGridView.RightToLeftInternal && (cellStyle.Alignment & anyRight) != 0) || (this.DataGridView.RightToLeftInternal && (cellStyle.Alignment & anyLeft) != 0)) { checkBoxX = valBounds.Right - checkBoxSize.Width; } else if ((cellStyle.Alignment & anyCenter) != 0) { checkBoxX = valBounds.Left + (valBounds.Width - checkBoxSize.Width) / 2; } else { checkBoxX = valBounds.Left; } if ((cellStyle.Alignment & anyBottom) != 0) { checkBoxY = valBounds.Bottom - checkBoxSize.Height; } else if ((cellStyle.Alignment & anyMiddle) != 0) { checkBoxY = valBounds.Top + (valBounds.Height - checkBoxSize.Height) / 2; } else { checkBoxY = valBounds.Top; } if (this.DataGridView.ApplyVisualStylesToInnerCells && this.FlatStyle != FlatStyle.Flat && this.FlatStyle != FlatStyle.Popup) { if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { DataGridViewCheckBoxCellRenderer.DrawCheckBox(g, new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height), (int) themeCheckBoxState); } resultBounds = new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height); } else { if (this.FlatStyle == FlatStyle.System || this.FlatStyle == FlatStyle.Standard) { if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { if (drawAsMixedCheckBox) { ControlPaint.DrawMixedCheckBox(g, checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height, bs); } else { ControlPaint.DrawCheckBox(g, checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height, bs); } } resultBounds = new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height); } else if (this.FlatStyle == FlatStyle.Flat) { // CheckBox::Paint will only paint the check box differently when in FlatStyle.Flat // this code is copied from CheckBox::DrawCheckFlat. it was a lot of trouble making this function static Rectangle checkBounds = new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width, checkBoxSize.Height); SolidBrush foreBrush = null; SolidBrush backBrush = null; Color highlight = Color.Empty; if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { foreBrush = this.DataGridView.GetCachedBrush(cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor); backBrush = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); highlight = ControlPaint.LightLight(backBrush.Color); if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInContentBounds) { const float lowlight = .1f; float adjust = 1 - lowlight; if (highlight.GetBrightness() < .5) { adjust = 1 + lowlight * 2; } highlight = Color.FromArgb(ButtonInternal.ButtonBaseAdapter.ColorOptions.Adjust255(adjust, highlight.R), ButtonInternal.ButtonBaseAdapter.ColorOptions.Adjust255(adjust, highlight.G), ButtonInternal.ButtonBaseAdapter.ColorOptions.Adjust255(adjust, highlight.B)); } highlight = g.GetNearestColor(highlight); using (Pen pen = new Pen(foreBrush.Color)) { g.DrawLine(pen, checkBounds.Left, checkBounds.Top, checkBounds.Right-1, checkBounds.Top); g.DrawLine(pen, checkBounds.Left, checkBounds.Top, checkBounds.Left, checkBounds.Bottom-1); } } checkBounds.Inflate(-1, -1); checkBounds.Width++; checkBounds.Height++; if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { if (checkState == CheckState.Indeterminate) { ButtonInternal.ButtonBaseAdapter.DrawDitheredFill(g, backBrush.Color, highlight, checkBounds); } else { using (SolidBrush highBrush = new SolidBrush(highlight)) { g.FillRectangle(highBrush, checkBounds); } } // draw the check box if (checkState != CheckState.Unchecked) { Rectangle fullSize = new Rectangle(checkBoxX-1, checkBoxY-1, checkBoxSize.Width+3, checkBoxSize.Height+3); fullSize.Width++; fullSize.Height++; if (checkImage == null || checkImage.Width != fullSize.Width || checkImage.Height != fullSize.Height) { if (checkImage != null) { checkImage.Dispose(); checkImage = null; } // We draw the checkmark slightly off center to eliminate 3-D border artifacts, // and compensate below NativeMethods.RECT rcCheck = NativeMethods.RECT.FromXYWH(0, 0, fullSize.Width, fullSize.Height); Bitmap bitmap = new Bitmap(fullSize.Width, fullSize.Height); using (Graphics offscreen = Graphics.FromImage(bitmap)) { offscreen.Clear(Color.Transparent); IntPtr dc = offscreen.GetHdc(); try { SafeNativeMethods.DrawFrameControl(new HandleRef(offscreen, dc), ref rcCheck, NativeMethods.DFC_MENU, NativeMethods.DFCS_MENUCHECK); } finally { offscreen.ReleaseHdcInternal(dc); } } bitmap.MakeTransparent(); checkImage = bitmap; } fullSize.Y--; ControlPaint.DrawImageColorized(g, checkImage, fullSize, checkState == CheckState.Indeterminate ? ControlPaint.LightLight(foreBrush.Color) : foreBrush.Color); } } resultBounds = checkBounds; } else { Debug.Assert(this.FlatStyle == FlatStyle.Popup); Rectangle checkBounds = new Rectangle(checkBoxX, checkBoxY, checkBoxSize.Width - 1, checkBoxSize.Height - 1); // The CheckBoxAdapter code moves the check box down about 3 pixels so we have to take that into account checkBounds.Y -= 3; if ((this.ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0) { // paint down ButtonBaseAdapter.LayoutOptions options = ButtonInternal.CheckBoxPopupAdapter.PaintPopupLayout(g, true /*show3D*/, checkBoxSize.Width, checkBounds, Padding.Empty, false, cellStyle.Font, String.Empty, this.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), this.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData layout = options.Layout(); if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); CheckBoxBaseAdapter.DrawCheckBackground(this.DataGridView.Enabled, checkState, g, layout.checkBounds, colors.windowText, colors.buttonFace, true /*disabledColors*/, colors); CheckBoxBaseAdapter.DrawPopupBorder(g, layout.checkBounds, colors); CheckBoxBaseAdapter.DrawCheckOnly(checkBoxSize.Width, checkState == CheckState.Checked || checkState == CheckState.Indeterminate, this.DataGridView.Enabled, checkState, g, layout, colors, colors.windowText, colors.buttonFace, true /*disabledColors*/); } resultBounds = layout.checkBounds; } else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInContentBounds) { // paint over ButtonBaseAdapter.LayoutOptions options = ButtonInternal.CheckBoxPopupAdapter.PaintPopupLayout(g, true /*show3D*/, checkBoxSize.Width, checkBounds, Padding.Empty, false, cellStyle.Font, String.Empty, this.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), this.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData layout = options.Layout(); if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); CheckBoxBaseAdapter.DrawCheckBackground(this.DataGridView.Enabled, checkState, g, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true /*disabledColors*/, colors); CheckBoxBaseAdapter.DrawPopupBorder(g, layout.checkBounds, colors); CheckBoxBaseAdapter.DrawCheckOnly(checkBoxSize.Width, checkState == CheckState.Checked || checkState == CheckState.Indeterminate, this.DataGridView.Enabled, checkState, g, layout, colors, colors.windowText, colors.highlight, true /*disabledColors*/); } resultBounds = layout.checkBounds; } else { // paint up ButtonBaseAdapter.LayoutOptions options = ButtonInternal.CheckBoxPopupAdapter.PaintPopupLayout(g, false /*show3D*/, checkBoxSize.Width, checkBounds, Padding.Empty, false, cellStyle.Font, String.Empty, this.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), this.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData layout = options.Layout(); if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, this.DataGridView.Enabled).Calculate(); CheckBoxBaseAdapter.DrawCheckBackground(this.DataGridView.Enabled, checkState, g, layout.checkBounds, colors.windowText, colors.options.highContrast ? colors.buttonFace : colors.highlight, true /*disabledColors*/, colors); ButtonBaseAdapter.DrawFlatBorder(g, layout.checkBounds, colors.buttonShadow); CheckBoxBaseAdapter.DrawCheckOnly(checkBoxSize.Width, checkState == CheckState.Checked || checkState == CheckState.Indeterminate, this.DataGridView.Enabled, checkState, g, layout, colors, colors.windowText, colors.highlight, true /*disabledColors*/); } resultBounds = layout.checkBounds; } } } } else if (computeErrorIconBounds) { if (!String.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } else { resultBounds = Rectangle.Empty; } } else { Debug.Assert(valBounds.Width < checkBoxSize.Width || valBounds.Height < checkBoxSize.Height, "the bounds are empty"); resultBounds = Rectangle.Empty; } if (paint && DataGridViewCell.PaintErrorIcon(paintParts) && drawErrorText && this.DataGridView.ShowCellErrors) { PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText); } return resultBounds; }
private static Color GetAlphaBlendedColorHighRes(Graphics graphics, Color src, Color dest, int alpha) { int factor = 100; int inv_alpha = 100 - alpha; if (alpha >= 100) { inv_alpha = 1000 - alpha; factor = 1000; } int r = (((alpha * src.R) + (inv_alpha * dest.R)) + (factor / 2)) / factor; int g = (((alpha * src.G) + (inv_alpha * dest.G)) + (factor / 2)) / factor; int b = (((alpha * src.B) + (inv_alpha * dest.B)) + (factor / 2)) / factor; if (graphics == null) return Color.FromArgb(r, g, b); else return graphics.GetNearestColor(Color.FromArgb(r, g, b)); }
public void Paint(Graphics g) { if (DisplayRectangle.IsEmpty) return; int x=DisplayRectangle.X; int y=DisplayRectangle.Y; Color colorDark=g.GetNearestColor(ControlPaint.Light(m_Parent.ColorScheme.TabItemText)); //Color colorBorder=g.GetNearestColor(ControlPaint.LightLight(m_Parent.ColorScheme.TabBackground)); if(Math.Abs(colorDark.GetBrightness()-m_Parent.ColorScheme.TabBackground.GetBrightness())<=.2) colorDark=(m_Parent.ColorScheme.TabBackground.GetBrightness()<.5?ControlPaint.Light(m_Parent.ColorScheme.TabBackground):ControlPaint.Dark(m_Parent.ColorScheme.TabBackground)); SolidBrush brush=null; Pen pen=new Pen(colorDark,1); if(BackEnabled || ForwardEnabled) brush=new SolidBrush(colorDark); if(m_Parent.TabAlignment==eTabStripAlignment.Left || m_Parent.TabAlignment==eTabStripAlignment.Right) { // Offset position to center the system items... y+=(DisplayRectangle.Height-(m_CloseVisible?32:18))/2; x+=(DisplayRectangle.Width-9)/2; Point[] p=new Point[3]; p[0].X=x+4; p[0].Y=y; p[1].X=x; p[1].Y=y+4; p[2].X=x+8; p[2].Y=y+4; m_BackRect=new Rectangle(x-3,y-5,14,14); if(BackEnabled) { if(m_BackMouseState==eMouseState.Hot) DrawBackgroundHot(g,m_BackRect); // BarFunctions.DrawBorder3D(g,m_BackRect,Border3DStyle.RaisedInner,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); else if(m_BackMouseState==eMouseState.Down) DrawBackgroundPressed(g,m_BackRect); // BarFunctions.DrawBorder3D(g,m_BackRect,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); g.FillPolygon(brush,p); } g.DrawPolygon(pen,p); y+=14; p[0].X=x; p[0].Y=y; p[1].X=x+8; p[1].Y=y; p[2].X=x+4; p[2].Y=y+4; m_ForwardRect=new Rectangle(x-3,y-5,14,14); if(ForwardEnabled) { if(m_ForwardMouseState==eMouseState.Hot) DrawBackgroundHot(g,m_ForwardRect); // BarFunctions.DrawBorder3D(g,m_ForwardRect,Border3DStyle.RaisedInner,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); else if(m_ForwardMouseState==eMouseState.Down) DrawBackgroundPressed(g,m_ForwardRect); // BarFunctions.DrawBorder3D(g,m_ForwardRect,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); g.FillPolygon(brush,p); } g.DrawPolygon(pen,p); y+=13; if(CloseVisible) { m_CloseRect=new Rectangle(x-3,y-3,14,14); if(CloseVisible) { if(m_CloseMouseState==eMouseState.Hot) DrawBackgroundHot(g,m_CloseRect); // BarFunctions.DrawBorder3D(g,m_CloseRect,Border3DStyle.RaisedInner,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); else if(m_CloseMouseState==eMouseState.Down) DrawBackgroundPressed(g,m_CloseRect); //BarFunctions.DrawBorder3D(g,m_CloseRect,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); } g.DrawLine(pen,x+1,y,x+7,y+6); g.DrawLine(pen,x+1,y+1,x+7,y+7); g.DrawLine(pen,x+1,y+6,x+7,y); g.DrawLine(pen,x+1,y+7,x+7,y+1); } } else { // Offset position to center the system items... x+=(DisplayRectangle.Width-(m_CloseVisible?32:18))/2; y+=(DisplayRectangle.Height-9)/2; Point[] p=new Point[3]; p[0].X=x+4; p[0].Y=y; p[1].X=x+4; p[1].Y=y+8; p[2].X=x; p[2].Y=y+4; m_BackRect=new Rectangle(x-5,y-3,14,14); if(BackEnabled) { if(m_BackMouseState==eMouseState.Hot) DrawBackgroundHot(g,m_BackRect); // BarFunctions.DrawBorder3D(g,m_BackRect,Border3DStyle.RaisedInner,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); else if(m_BackMouseState==eMouseState.Down) DrawBackgroundPressed(g,m_BackRect); // BarFunctions.DrawBorder3D(g,m_BackRect,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); g.FillPolygon(brush,p); } g.DrawPolygon(pen,p); x+=14; p[0].X=x; p[0].Y=y; p[1].X=x; p[1].Y=y+8; p[2].X=x+4; p[2].Y=y+4; m_ForwardRect=new Rectangle(x-5,y-3,14,14); if(ForwardEnabled) { if(m_ForwardMouseState==eMouseState.Hot) DrawBackgroundHot(g,m_ForwardRect); // BarFunctions.DrawBorder3D(g,m_ForwardRect,Border3DStyle.RaisedInner,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); else if(m_ForwardMouseState==eMouseState.Down) DrawBackgroundPressed(g,m_ForwardRect); // BarFunctions.DrawBorder3D(g,m_ForwardRect,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); g.FillPolygon(brush,p); } g.DrawPolygon(pen,p); x+=13; if(CloseVisible) { m_CloseRect=new Rectangle(x-4,y-3,14,14); if(CloseVisible) { if(m_CloseMouseState==eMouseState.Hot) DrawBackgroundHot(g,m_CloseRect); // BarFunctions.DrawBorder3D(g,m_CloseRect,Border3DStyle.RaisedInner,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); else if(m_CloseMouseState==eMouseState.Down) DrawBackgroundPressed(g,m_CloseRect); // BarFunctions.DrawBorder3D(g,m_CloseRect,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); } g.DrawLine(pen,x,y+1,x+6,y+7); g.DrawLine(pen,x+1,y+1,x+7,y+7); g.DrawLine(pen,x+6,y+1,x,y+7); g.DrawLine(pen,x+7,y+1,x+1,y+7); } } pen.Dispose(); if(brush!=null) brush.Dispose(); }
// this particular method gets us closer to office by increasing the resolution... private static Color GetAlphaBlendedColorHighRes(Graphics graphics, Color src, Color dest, int alpha) { int sum; int nPart2; int r, g, b; int nPart1 = alpha; if (nPart1 < 100) { nPart2 = 100 - nPart1; sum = 100; } else { nPart2 = 1000 - nPart1; sum = 1000; } // By adding on sum/2 before dividing by sum, we properly round the value, // rather than truncating it, while doing integer math. r = (nPart1 * src.R + nPart2 * dest.R + sum / 2) / sum; g = (nPart1 * src.G + nPart2 * dest.G + sum / 2) / sum; b = (nPart1 * src.B + nPart2 * dest.B + sum / 2) / sum; if (graphics == null) { return Color.FromArgb(r, g, b); } else { return graphics.GetNearestColor(Color.FromArgb(r, g, b)); } }
/* public virtual Color ControlLight { get { return FromKnownColor(KnownColors.msocbvcrCBCtlBkgdLight); } } */ private static Color GetAlphaBlendedColor(Graphics g, Color src, Color dest, int alpha) { int red = (src.R * alpha + (255 - alpha) * dest.R) / 255; int green = (src.G * alpha + (255 - alpha) * dest.G) / 255; int blue = (src.B * alpha + (255 - alpha) * dest.B) / 255; int newAlpha = (src.A * alpha + (255 - alpha) * dest.A) / 255; if (g == null) { return Color.FromArgb(newAlpha, red, green, blue); } else { return g.GetNearestColor(Color.FromArgb(newAlpha, red, green, blue)); } }
private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint) { Rectangle checkBounds; CheckState @unchecked; System.Windows.Forms.ButtonState normal; Size glyphSize; if (paint && DataGridViewCell.PaintBorder(paintParts)) { this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle rectangle2 = cellBounds; Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle); rectangle2.Offset(rectangle3.X, rectangle3.Y); rectangle2.Width -= rectangle3.Right; rectangle2.Height -= rectangle3.Bottom; bool flag = (elementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None; bool isMixed = false; bool flag3 = true; Point currentCellAddress = base.DataGridView.CurrentCellAddress; if (((currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex)) && base.DataGridView.IsCurrentCellInEditMode) { flag3 = false; } if ((formattedValue != null) && (formattedValue is CheckState)) { @unchecked = (CheckState) formattedValue; normal = (@unchecked == CheckState.Unchecked) ? System.Windows.Forms.ButtonState.Normal : System.Windows.Forms.ButtonState.Checked; isMixed = @unchecked == CheckState.Indeterminate; } else if ((formattedValue != null) && (formattedValue is bool)) { if ((bool) formattedValue) { @unchecked = CheckState.Checked; normal = System.Windows.Forms.ButtonState.Checked; } else { @unchecked = CheckState.Unchecked; normal = System.Windows.Forms.ButtonState.Normal; } } else { normal = System.Windows.Forms.ButtonState.Normal; @unchecked = CheckState.Unchecked; } if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { normal |= System.Windows.Forms.ButtonState.Pushed; } SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff)) { g.FillRectangle(cachedBrush, rectangle2); } if (cellStyle.Padding != Padding.Empty) { if (base.DataGridView.RightToLeftInternal) { rectangle2.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { rectangle2.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } rectangle2.Width -= cellStyle.Padding.Horizontal; rectangle2.Height -= cellStyle.Padding.Vertical; } if (((paint && DataGridViewCell.PaintFocus(paintParts)) && (base.DataGridView.ShowFocusCues && base.DataGridView.Focused)) && ((currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex))) { ControlPaint.DrawFocusRectangle(g, rectangle2, Color.Empty, cachedBrush.Color); } Rectangle cellValueBounds = rectangle2; rectangle2.Inflate(-2, -2); CheckBoxState uncheckedNormal = CheckBoxState.UncheckedNormal; if (base.DataGridView.ApplyVisualStylesToInnerCells) { uncheckedNormal = CheckBoxRenderer.ConvertFromButtonState(normal, isMixed, ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds); glyphSize = CheckBoxRenderer.GetGlyphSize(g, uncheckedNormal); switch (this.FlatStyle) { case System.Windows.Forms.FlatStyle.Flat: glyphSize.Width -= 3; glyphSize.Height -= 3; break; case System.Windows.Forms.FlatStyle.Popup: glyphSize.Width -= 2; glyphSize.Height -= 2; break; } } else { switch (this.FlatStyle) { case System.Windows.Forms.FlatStyle.Flat: glyphSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal); glyphSize.Width -= 3; glyphSize.Height -= 3; goto Label_03EF; case System.Windows.Forms.FlatStyle.Popup: glyphSize = CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.UncheckedNormal); glyphSize.Width -= 2; glyphSize.Height -= 2; goto Label_03EF; } glyphSize = new Size((SystemInformation.Border3DSize.Width * 2) + 9, (SystemInformation.Border3DSize.Width * 2) + 9); } Label_03EF: if (((rectangle2.Width >= glyphSize.Width) && (rectangle2.Height >= glyphSize.Height)) && (paint || computeContentBounds)) { int x = 0; int y = 0; if ((!base.DataGridView.RightToLeftInternal && ((cellStyle.Alignment & anyRight) != DataGridViewContentAlignment.NotSet)) || (base.DataGridView.RightToLeftInternal && ((cellStyle.Alignment & anyLeft) != DataGridViewContentAlignment.NotSet))) { x = rectangle2.Right - glyphSize.Width; } else if ((cellStyle.Alignment & anyCenter) != DataGridViewContentAlignment.NotSet) { x = rectangle2.Left + ((rectangle2.Width - glyphSize.Width) / 2); } else { x = rectangle2.Left; } if ((cellStyle.Alignment & anyBottom) != DataGridViewContentAlignment.NotSet) { y = rectangle2.Bottom - glyphSize.Height; } else if ((cellStyle.Alignment & anyMiddle) != DataGridViewContentAlignment.NotSet) { y = rectangle2.Top + ((rectangle2.Height - glyphSize.Height) / 2); } else { y = rectangle2.Top; } if ((base.DataGridView.ApplyVisualStylesToInnerCells && (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Popup)) { if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { DataGridViewCheckBoxCellRenderer.DrawCheckBox(g, new Rectangle(x, y, glyphSize.Width, glyphSize.Height), (int) uncheckedNormal); } checkBounds = new Rectangle(x, y, glyphSize.Width, glyphSize.Height); } else if ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard)) { if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { if (isMixed) { ControlPaint.DrawMixedCheckBox(g, x, y, glyphSize.Width, glyphSize.Height, normal); } else { ControlPaint.DrawCheckBox(g, x, y, glyphSize.Width, glyphSize.Height, normal); } } checkBounds = new Rectangle(x, y, glyphSize.Width, glyphSize.Height); } else if (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) { Rectangle bounds = new Rectangle(x, y, glyphSize.Width, glyphSize.Height); SolidBrush brush2 = null; SolidBrush brush3 = null; Color empty = Color.Empty; if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { brush2 = base.DataGridView.GetCachedBrush(flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor); brush3 = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); empty = ControlPaint.LightLight(brush3.Color); if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { float percentage = 0.9f; if (empty.GetBrightness() < 0.5) { percentage = 1.2f; } empty = Color.FromArgb(ButtonBaseAdapter.ColorOptions.Adjust255(percentage, empty.R), ButtonBaseAdapter.ColorOptions.Adjust255(percentage, empty.G), ButtonBaseAdapter.ColorOptions.Adjust255(percentage, empty.B)); } empty = g.GetNearestColor(empty); using (Pen pen = new Pen(brush2.Color)) { g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Right - 1, bounds.Top); g.DrawLine(pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 1); } } bounds.Inflate(-1, -1); bounds.Width++; bounds.Height++; if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { if (@unchecked == CheckState.Indeterminate) { ButtonBaseAdapter.DrawDitheredFill(g, brush3.Color, empty, bounds); } else { using (SolidBrush brush4 = new SolidBrush(empty)) { g.FillRectangle(brush4, bounds); } } if (@unchecked != CheckState.Unchecked) { Rectangle destination = new Rectangle(x - 1, y - 1, glyphSize.Width + 3, glyphSize.Height + 3); destination.Width++; destination.Height++; if (((checkImage == null) || (checkImage.Width != destination.Width)) || (checkImage.Height != destination.Height)) { if (checkImage != null) { checkImage.Dispose(); checkImage = null; } System.Windows.Forms.NativeMethods.RECT rect = System.Windows.Forms.NativeMethods.RECT.FromXYWH(0, 0, destination.Width, destination.Height); Bitmap image = new Bitmap(destination.Width, destination.Height); using (Graphics graphics = Graphics.FromImage(image)) { graphics.Clear(Color.Transparent); IntPtr hdc = graphics.GetHdc(); try { System.Windows.Forms.SafeNativeMethods.DrawFrameControl(new HandleRef(graphics, hdc), ref rect, 2, 1); } finally { graphics.ReleaseHdcInternal(hdc); } } image.MakeTransparent(); checkImage = image; } destination.Y--; ControlPaint.DrawImageColorized(g, checkImage, destination, (@unchecked == CheckState.Indeterminate) ? ControlPaint.LightLight(brush2.Color) : brush2.Color); } } checkBounds = bounds; } else { Rectangle rectangle7; rectangle7 = new Rectangle(x, y, glyphSize.Width - 1, glyphSize.Height - 1) { Y = rectangle7.Y - 3 }; if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { ButtonBaseAdapter.LayoutOptions options = CheckBoxPopupAdapter.PaintPopupLayout(g, true, glyphSize.Width, rectangle7, Padding.Empty, false, cellStyle.Font, string.Empty, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData layout = options.Layout(); if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); CheckBoxBaseAdapter.DrawCheckBackground(base.DataGridView.Enabled, @unchecked, g, layout.checkBounds, colors.windowText, colors.buttonFace, true, colors); CheckBoxBaseAdapter.DrawPopupBorder(g, layout.checkBounds, colors); CheckBoxBaseAdapter.DrawCheckOnly(glyphSize.Width, (@unchecked == CheckState.Checked) || (@unchecked == CheckState.Indeterminate), base.DataGridView.Enabled, @unchecked, g, layout, colors, colors.windowText, colors.buttonFace, true); } checkBounds = layout.checkBounds; } else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { ButtonBaseAdapter.LayoutOptions options2 = CheckBoxPopupAdapter.PaintPopupLayout(g, true, glyphSize.Width, rectangle7, Padding.Empty, false, cellStyle.Font, string.Empty, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options2.everettButtonCompat = false; ButtonBaseAdapter.LayoutData data3 = options2.Layout(); if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { ButtonBaseAdapter.ColorData data4 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); CheckBoxBaseAdapter.DrawCheckBackground(base.DataGridView.Enabled, @unchecked, g, data3.checkBounds, data4.windowText, data4.options.highContrast ? data4.buttonFace : data4.highlight, true, data4); CheckBoxBaseAdapter.DrawPopupBorder(g, data3.checkBounds, data4); CheckBoxBaseAdapter.DrawCheckOnly(glyphSize.Width, (@unchecked == CheckState.Checked) || (@unchecked == CheckState.Indeterminate), base.DataGridView.Enabled, @unchecked, g, data3, data4, data4.windowText, data4.highlight, true); } checkBounds = data3.checkBounds; } else { ButtonBaseAdapter.LayoutOptions options3 = CheckBoxPopupAdapter.PaintPopupLayout(g, false, glyphSize.Width, rectangle7, Padding.Empty, false, cellStyle.Font, string.Empty, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options3.everettButtonCompat = false; ButtonBaseAdapter.LayoutData data5 = options3.Layout(); if (paint && DataGridViewCell.PaintContentForeground(paintParts)) { ButtonBaseAdapter.ColorData data6 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); CheckBoxBaseAdapter.DrawCheckBackground(base.DataGridView.Enabled, @unchecked, g, data5.checkBounds, data6.windowText, data6.options.highContrast ? data6.buttonFace : data6.highlight, true, data6); ButtonBaseAdapter.DrawFlatBorder(g, data5.checkBounds, data6.buttonShadow); CheckBoxBaseAdapter.DrawCheckOnly(glyphSize.Width, (@unchecked == CheckState.Checked) || (@unchecked == CheckState.Indeterminate), base.DataGridView.Enabled, @unchecked, g, data5, data6, data6.windowText, data6.highlight, true); } checkBounds = data5.checkBounds; } } } else if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { checkBounds = base.ComputeErrorIconBounds(cellValueBounds); } else { checkBounds = Rectangle.Empty; } } else { checkBounds = Rectangle.Empty; } if ((paint && DataGridViewCell.PaintErrorIcon(paintParts)) && (flag3 && base.DataGridView.ShowCellErrors)) { base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText); } return checkBounds; }
public override void PaintOutline(System.Drawing.Graphics g, Rectangle r) { // draw outline pointer triangle. if (Expandable) { bool fExpanded = Expanded; Rectangle outline = OutlineRect; // make sure we're in our bounds outline = Rectangle.Intersect(r, outline); if (outline.IsEmpty) { return; } #if PAINT_CATEGORY_TRIANGLE // bump it over a pixel //outline.Offset(1, 0); //outline.Inflate(-1,-1); // build the triangle, an equalaterial centered around the midpoint of the rect. Point[] points = new Point[3]; int borderWidth = 2; // width is always the length of the sides of the triangle. // Height = (width /2 * (Cos60)) ; Cos60 ~ .86 int triWidth, triHeight; int xOffset, yOffset; if (!fExpanded) { // draw arrow pointing right, remember height is pointing right // 0 // |\ // | \2 // | / // |/ // 1 triWidth = (int)((outline.Height * TRI_WIDTH_RATIO) - (2 * borderWidth)); // make sure it's an odd width so our lines will match up if (!(triWidth % 2 == 0)) { triWidth++; } triHeight = (int)Math.Ceil((triWidth / 2) * TRI_HEIGHT_RATIO); yOffset = outline.Y + (outline.Height - triWidth) / 2; xOffset = outline.X + (outline.Width - triHeight) / 2; points[0] = new Point(xOffset, yOffset); points[1] = new Point(xOffset, yOffset + triWidth); points[2] = new Point(xOffset + triHeight, yOffset + (triWidth / 2)); } else { // draw arrow pointing down // 0 -------- 1 // \ / // \ / // \ / // \/ // 2 triWidth = (int)((outline.Width * TRI_WIDTH_RATIO) - (2 * borderWidth)); // make sure it's an odd width so our lines will match up if (!(triWidth % 2 == 0)) { triWidth++; } triHeight = (int)Math.Ceil((triWidth / 2) * TRI_HEIGHT_RATIO); xOffset = outline.X + (outline.Width - triWidth) / 2; yOffset = outline.Y + (outline.Height - triHeight) / 2; points[0] = new Point(xOffset, yOffset); points[1] = new Point(xOffset + triWidth, yOffset); points[2] = new Point(xOffset + (triWidth / 2), yOffset + triHeight); } g.FillPolygon(SystemPens.WindowText, points); #else // draw border area box Brush b; Pen p; bool disposeBrush = false; bool disposePen = false; Color color = GridEntryHost.GetLineColor(); b = new SolidBrush(g.GetNearestColor(color)); disposeBrush = true; color = GridEntryHost.GetTextColor(); p = new Pen(g.GetNearestColor(color)); disposePen = true; g.FillRectangle(b, outline); g.DrawRectangle(p, outline.X, outline.Y, outline.Width - 1, outline.Height - 1); // draw horizontal line for +/- int indent = 2; g.DrawLine(SystemPens.WindowText, outline.X + indent, outline.Y + outline.Height / 2, outline.X + outline.Width - indent - 1, outline.Y + outline.Height / 2); // draw vertical line to make a + if (!fExpanded) { g.DrawLine(SystemPens.WindowText, outline.X + outline.Width / 2, outline.Y + indent, outline.X + outline.Width / 2, outline.Y + outline.Height - indent - 1); } if (disposePen) { p.Dispose(); } if (disposeBrush) { b.Dispose(); } #endif } }
private void DrawBackgroundPressed(Graphics g, Rectangle r) { Color border=m_Parent.ColorScheme.TabItemHotBorder; Color back=m_Parent.ColorScheme.TabItemHotBackground; Color back2=m_Parent.ColorScheme.TabItemHotBackground2; if((m_Parent.Style==eTabStripStyle.Office2003 || m_Parent.Style==eTabStripStyle.VS2005 || m_Parent.Style==eTabStripStyle.VS2005Document || m_Parent.Style==eTabStripStyle.VS2005Dock)&& back.IsEmpty && back2.IsEmpty) { ColorScheme cs; if(m_Parent.Style==eTabStripStyle.Office2003) cs=new ColorScheme(eDotNetBarStyle.Office2003); else cs=new ColorScheme(eDotNetBarStyle.VS2005); back=cs.ItemPressedBackground; back2=cs.ItemPressedBackground2; border=cs.ItemPressedBorder; } if (m_Parent.Style == eTabStripStyle.OneNote || m_Parent.Style == eTabStripStyle.Office2007Document || m_Parent.Style == eTabStripStyle.Office2007Dock || m_Parent.Style == eTabStripStyle.Office2003 || m_Parent.Style == eTabStripStyle.VS2005 || m_Parent.Style == eTabStripStyle.VS2005 || m_Parent.Style == eTabStripStyle.VS2005Document) { if(back2.IsEmpty) { if(!back.IsEmpty) { using(SolidBrush brush=new SolidBrush(back)) g.FillRectangle(brush,r); } } else { using(LinearGradientBrush brush=new LinearGradientBrush(r,back2,back,m_Parent.ColorScheme.TabItemHotBackgroundGradientAngle)) g.FillRectangle(brush,r); } using(Pen pen=new Pen(border,1)) g.DrawRectangle(pen,r); } else { Color colorBorder=g.GetNearestColor(ControlPaint.LightLight(m_Parent.ColorScheme.TabBackground)); BarFunctions.DrawBorder3D(g,r,Border3DStyle.SunkenOuter,Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom,colorBorder,false); } }
public virtual Brush GetSelectedItemWithFocusBackBrush(Graphics g) { if (ownerGrid.selectedItemWithFocusBackBrush == null) { Color clr = g.GetNearestColor(ownerGrid.SelectedItemWithFocusBackColor); ownerGrid.selectedItemWithFocusBackBrush = new SolidBrush(clr); } return ownerGrid.selectedItemWithFocusBackBrush; }
private static Color GetAlphaBlendedColor(Graphics graphics, Color src, Color dest, int alpha) { int r = ((src.R * alpha) + ((255 - alpha) * dest.R)) / 255; int g = ((src.G * alpha) + ((255 - alpha) * dest.G)) / 255; int b = ((src.B * alpha) + ((255 - alpha) * dest.B)) / 255; int a = ((src.A * alpha) + ((255 - alpha) * dest.A)) / 255; if (graphics == null) return Color.FromArgb(a, r, g, b); else return graphics.GetNearestColor(Color.FromArgb(a, r, g, b)); }
// PaintPrivate is used in four places that need to duplicate the paint code: // 1. DataGridViewCell::Paint method // 2. DataGridViewCell::GetContentBounds // 3. DataGridViewCell::GetErrorIconBounds // 4. DataGridViewCell::OnMouseMove - to compute the dropDownButtonRect // // if computeContentBounds is true then PaintPrivate returns the contentBounds // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds // else it returns Rectangle.Empty; // // PaintPrivate uses the computeDropDownButtonRect to determine if it should compute the dropDownButtonRect private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, out Rectangle dropDownButtonRect, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool computeDropDownButtonRect, bool paint) { // Parameter checking. // One bit and one bit only should be turned on Debug.Assert(paint || computeContentBounds || computeErrorIconBounds || computeDropDownButtonRect); Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds || !computeDropDownButtonRect); Debug.Assert(!paint || !computeContentBounds || !computeDropDownButtonRect || !computeErrorIconBounds); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint || !computeDropDownButtonRect); Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !computeDropDownButtonRect || !paint); Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds || !computeDropDownButtonRect); Debug.Assert(!computeErrorIconBounds || !paint || !computeDropDownButtonRect || !computeContentBounds); Debug.Assert(cellStyle != null); Rectangle resultBounds = Rectangle.Empty; dropDownButtonRect = Rectangle.Empty; bool paintFlat = this.FlatStyle == FlatStyle.Flat || this.FlatStyle == FlatStyle.Popup; bool paintPopup = this.FlatStyle == FlatStyle.Popup && this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex; bool paintXPThemes = !paintFlat && this.DataGridView.ApplyVisualStylesToInnerCells; bool paintPostXPThemes = paintXPThemes && PostXPThemesExist; ComboBoxState comboBoxState = ComboBoxState.Normal; if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex && mouseInDropDownButtonBounds) { comboBoxState = ComboBoxState.Hot; } if (paint && DataGridViewCell.PaintBorder(paintParts)) { PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle borderWidths = BorderWidths(advancedBorderStyle); Rectangle valBounds = cellBounds; valBounds.Offset(borderWidths.X, borderWidths.Y); valBounds.Width -= borderWidths.Right; valBounds.Height -= borderWidths.Bottom; SolidBrush br; Point ptCurrentCell = this.DataGridView.CurrentCellAddress; bool cellCurrent = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex; bool cellEdited = cellCurrent && this.DataGridView.EditingControl != null; bool cellSelected = (elementState & DataGridViewElementStates.Selected) != 0; bool drawComboBox = this.DisplayStyle == DataGridViewComboBoxDisplayStyle.ComboBox && ((this.DisplayStyleForCurrentCellOnly && cellCurrent) || !this.DisplayStyleForCurrentCellOnly); bool drawDropDownButton = this.DisplayStyle != DataGridViewComboBoxDisplayStyle.Nothing && ((this.DisplayStyleForCurrentCellOnly && cellCurrent) || !this.DisplayStyleForCurrentCellOnly); if (DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected && !cellEdited) { br = this.DataGridView.GetCachedBrush(cellStyle.SelectionBackColor); } else { br = this.DataGridView.GetCachedBrush(cellStyle.BackColor); } if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255 && valBounds.Width > 0 && valBounds.Height > 0) { DataGridViewCell.PaintPadding(g, valBounds, cellStyle, br, this.DataGridView.RightToLeftInternal); } if (cellStyle.Padding != Padding.Empty) { if (this.DataGridView.RightToLeftInternal) { valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } valBounds.Width -= cellStyle.Padding.Horizontal; valBounds.Height -= cellStyle.Padding.Vertical; } if (paint && valBounds.Width > 0 && valBounds.Height > 0) { if (paintXPThemes && drawComboBox) { if (paintPostXPThemes && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { g.FillRectangle(br, valBounds.Left, valBounds.Top, valBounds.Width, valBounds.Height); } if (DataGridViewCell.PaintContentBackground(paintParts)) { if (paintPostXPThemes) { DataGridViewComboBoxCellRenderer.DrawBorder(g, valBounds); } else { DataGridViewComboBoxCellRenderer.DrawTextBox(g, valBounds, comboBoxState); } } if (!paintPostXPThemes && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255 && valBounds.Width > 2 && valBounds.Height > 2) { g.FillRectangle(br, valBounds.Left + 1, valBounds.Top + 1, valBounds.Width - 2, valBounds.Height - 2); } } else if (DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255) { if (paintPostXPThemes && drawDropDownButton && !drawComboBox) { g.DrawRectangle(SystemPens.ControlLightLight, new Rectangle(valBounds.X, valBounds.Y, valBounds.Width-1, valBounds.Height-1)); } else { g.FillRectangle(br, valBounds.Left, valBounds.Top, valBounds.Width, valBounds.Height); } } } int dropWidth = Math.Min(SystemInformation.HorizontalScrollBarThumbWidth, valBounds.Width - 2 * DATAGRIDVIEWCOMBOBOXCELL_margin - 1); if (!cellEdited) { int dropHeight; if (paintXPThemes || paintFlat) { dropHeight = Math.Min(GetDropDownButtonHeight(g, cellStyle), paintPostXPThemes ? valBounds.Height : valBounds.Height - 2); } else { dropHeight = Math.Min(GetDropDownButtonHeight(g, cellStyle), valBounds.Height - 4); } if (dropWidth > 0 && dropHeight > 0) { Rectangle dropRect; if (paintXPThemes || paintFlat) { if (paintPostXPThemes) { dropRect = new Rectangle(this.DataGridView.RightToLeftInternal ? valBounds.Left : valBounds.Right - dropWidth, valBounds.Top, dropWidth, dropHeight); } else { dropRect = new Rectangle(this.DataGridView.RightToLeftInternal ? valBounds.Left + 1 : valBounds.Right - dropWidth - 1, valBounds.Top + 1, dropWidth, dropHeight); } } else { dropRect = new Rectangle(this.DataGridView.RightToLeftInternal ? valBounds.Left + 2 : valBounds.Right - dropWidth - 2, valBounds.Top + 2, dropWidth, dropHeight); } if (paintPostXPThemes && drawDropDownButton && !drawComboBox) { dropDownButtonRect = valBounds; } else { dropDownButtonRect = dropRect; } if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { if (drawDropDownButton) { if (paintFlat) { g.FillRectangle(SystemBrushes.Control, dropRect); } else if (paintXPThemes) { if (paintPostXPThemes) { if (drawComboBox) { DataGridViewComboBoxCellRenderer.DrawDropDownButton(g, dropRect, comboBoxState, this.DataGridView.RightToLeftInternal); } else { DataGridViewComboBoxCellRenderer.DrawReadOnlyButton(g, valBounds, comboBoxState); DataGridViewComboBoxCellRenderer.DrawDropDownButton(g, dropRect, ComboBoxState.Normal); } } else { DataGridViewComboBoxCellRenderer.DrawDropDownButton(g, dropRect, comboBoxState); } } else { g.FillRectangle(SystemBrushes.Control, dropRect); } } if (!paintFlat && !paintXPThemes && (drawComboBox || drawDropDownButton)) { // border painting is ripped from button renderer Color color= SystemColors.Control; Color buttonShadow; Color buttonShadowDark; Color buttonFace = color; Color highlight; bool stockColor = color.ToKnownColor() == SystemColors.Control.ToKnownColor(); bool highContrast = SystemInformation.HighContrast; if (color == SystemColors.Control) { buttonShadow = SystemColors.ControlDark; buttonShadowDark = SystemColors.ControlDarkDark; highlight = SystemColors.ControlLightLight; } else { buttonShadow = ControlPaint.Dark(color); highlight = ControlPaint.LightLight(color); if (highContrast) { buttonShadowDark = ControlPaint.LightLight(color); } else { buttonShadowDark = ControlPaint.DarkDark(color); } } buttonShadow = g.GetNearestColor(buttonShadow); buttonShadowDark = g.GetNearestColor(buttonShadowDark); buttonFace = g.GetNearestColor(buttonFace); highlight = g.GetNearestColor(highlight); // top + left Pen pen; if (stockColor) { if (SystemInformation.HighContrast) { pen = SystemPens.ControlLight; } else { pen = SystemPens.Control; } } else { pen= new Pen(highlight); } if (drawDropDownButton) { g.DrawLine(pen, dropRect.X, dropRect.Y, dropRect.X + dropRect.Width - 1, dropRect.Y); g.DrawLine(pen, dropRect.X, dropRect.Y, dropRect.X, dropRect.Y + dropRect.Height - 1); } // the bounds around the combobox control if (drawComboBox) { g.DrawLine(pen, valBounds.X, valBounds.Y + valBounds.Height - 1, valBounds.X + valBounds.Width - 1, valBounds.Y + valBounds.Height - 1); g.DrawLine(pen, valBounds.X + valBounds.Width - 1, valBounds.Y, valBounds.X + valBounds.Width - 1, valBounds.Y + valBounds.Height - 1); } // bottom + right if (stockColor) { pen = SystemPens.ControlDarkDark; } else { pen.Color = buttonShadowDark; } if (drawDropDownButton) { g.DrawLine(pen, dropRect.X, dropRect.Y + dropRect.Height - 1, dropRect.X + dropRect.Width - 1, dropRect.Y + dropRect.Height - 1); g.DrawLine(pen, dropRect.X + dropRect.Width - 1, dropRect.Y, dropRect.X + dropRect.Width - 1, dropRect.Y + dropRect.Height - 1); } // the bounds around the combobox control if (drawComboBox) { g.DrawLine(pen, valBounds.X, valBounds.Y, valBounds.X + valBounds.Width - 2, valBounds.Y); g.DrawLine(pen, valBounds.X, valBounds.Y, valBounds.X, valBounds.Y + valBounds.Height - 1); } // Top + Left inset if (stockColor) { pen = SystemPens.ControlLightLight; } else { pen.Color = buttonFace; } if (drawDropDownButton) { g.DrawLine(pen, dropRect.X + 1, dropRect.Y + 1, dropRect.X + dropRect.Width - 2, dropRect.Y + 1); g.DrawLine(pen, dropRect.X + 1, dropRect.Y + 1, dropRect.X + 1, dropRect.Y + dropRect.Height - 2); } // Bottom + Right inset if (stockColor) { pen = SystemPens.ControlDark; } else { pen.Color = buttonShadow; } if (drawDropDownButton) { g.DrawLine(pen, dropRect.X + 1, dropRect.Y + dropRect.Height - 2, dropRect.X + dropRect.Width - 2, dropRect.Y + dropRect.Height - 2); g.DrawLine(pen, dropRect.X + dropRect.Width - 2, dropRect.Y + 1, dropRect.X + dropRect.Width - 2, dropRect.Y + dropRect.Height - 2); } if (!stockColor) { pen.Dispose(); } } if (dropWidth >= 5 && dropHeight >= 3 && drawDropDownButton) { if (paintFlat) { Point middle = new Point(dropRect.Left + dropRect.Width / 2, dropRect.Top + dropRect.Height / 2); // if the width is odd - favor pushing it over one pixel right. middle.X += (dropRect.Width % 2); // if the height is odd - favor pushing it over one pixel down. middle.Y += (dropRect.Height % 2); g.FillPolygon(SystemBrushes.ControlText, new Point[] { new Point(middle.X - 2, middle.Y - 1), new Point(middle.X + 3, middle.Y - 1), new Point(middle.X, middle.Y + 2) }); } else if (!paintXPThemes) { // XPThemes already painted the drop down button // the down arrow looks better when it's fatten up by a pixel dropRect.X--; dropRect.Width++; Point middle = new Point(dropRect.Left + (dropRect.Width - 1) / 2, dropRect.Top + (dropRect.Height + DATAGRIDVIEWCOMBOBOXCELL_nonXPTriangleHeight) / 2); // if the width is event - favor pushing it over one pixel right. middle.X += ((dropRect.Width + 1) % 2); // if the height is odd - favor pushing it over one pixel down. middle.Y += (dropRect.Height % 2); Point pt1 = new Point(middle.X - (DATAGRIDVIEWCOMBOBOXCELL_nonXPTriangleWidth - 1) / 2, middle.Y - DATAGRIDVIEWCOMBOBOXCELL_nonXPTriangleHeight); Point pt2 = new Point(middle.X + (DATAGRIDVIEWCOMBOBOXCELL_nonXPTriangleWidth - 1) / 2, middle.Y - DATAGRIDVIEWCOMBOBOXCELL_nonXPTriangleHeight); g.FillPolygon(SystemBrushes.ControlText, new Point[] { pt1, pt2, middle }); // quirk in GDI+ : if we dont draw the line below then the top right most pixel of the DropDown triangle will not paint // Would think that g.FillPolygon would have painted that... g.DrawLine(SystemPens.ControlText, pt1.X, pt1.Y, pt2.X, pt2.Y); // slim down the drop rect dropRect.X++; dropRect.Width--; } } if (paintPopup && drawComboBox) { // draw a dark border around the dropdown rect if we are in popup mode dropRect.Y--; dropRect.Height++; g.DrawRectangle(SystemPens.ControlDark, dropRect); } } } } Rectangle errorBounds = valBounds; Rectangle textBounds = Rectangle.Inflate(valBounds, -2, -2); if (paintPostXPThemes) { if (!this.DataGridView.RightToLeftInternal) { textBounds.X--; } textBounds.Width++; } if (drawDropDownButton) { if (paintXPThemes || paintFlat) { errorBounds.Width -= dropWidth; textBounds.Width -= dropWidth; if (this.DataGridView.RightToLeftInternal) { errorBounds.X += dropWidth; textBounds.X += dropWidth; } } else { errorBounds.Width -= dropWidth + 1; textBounds.Width -= dropWidth + 1; if (this.DataGridView.RightToLeftInternal) { errorBounds.X += dropWidth + 1; textBounds.X += dropWidth + 1; } } } if (textBounds.Width > 1 && textBounds.Height > 1) { if (cellCurrent && !cellEdited && DataGridViewCell.PaintFocus(paintParts) && this.DataGridView.ShowFocusCues && this.DataGridView.Focused && paint) { // Draw focus rectangle if (paintFlat) { Rectangle focusBounds = textBounds; if (!this.DataGridView.RightToLeftInternal) { focusBounds.X--; } focusBounds.Width++; focusBounds.Y--; focusBounds.Height+=2; ControlPaint.DrawFocusRectangle(g, focusBounds, Color.Empty, br.Color); } else if (paintPostXPThemes) { Rectangle focusBounds = textBounds; focusBounds.X++; focusBounds.Width -= 2; focusBounds.Y++; focusBounds.Height -= 2; if (focusBounds.Width > 0 && focusBounds.Height > 0) { ControlPaint.DrawFocusRectangle(g, focusBounds, Color.Empty, br.Color); } } else { ControlPaint.DrawFocusRectangle(g, textBounds, Color.Empty, br.Color); } } if (paintPopup) { valBounds.Width--; valBounds.Height--; if (!cellEdited && paint && DataGridViewCell.PaintContentBackground(paintParts) && drawComboBox) { g.DrawRectangle(SystemPens.ControlDark, valBounds); } } string formattedString = formattedValue as string; if (formattedString != null) { // Font independent margins int verticalTextMarginTop = cellStyle.WrapMode == DataGridViewTriState.True ? DATAGRIDVIEWCOMBOBOXCELL_verticalTextMarginTopWithWrapping : DATAGRIDVIEWCOMBOBOXCELL_verticalTextMarginTopWithoutWrapping; if (this.DataGridView.RightToLeftInternal) { textBounds.Offset(DATAGRIDVIEWCOMBOBOXCELL_horizontalTextMarginLeft, verticalTextMarginTop); textBounds.Width += 2 - DATAGRIDVIEWCOMBOBOXCELL_horizontalTextMarginLeft; } else { textBounds.Offset(DATAGRIDVIEWCOMBOBOXCELL_horizontalTextMarginLeft - 1, verticalTextMarginTop); textBounds.Width += 1 - DATAGRIDVIEWCOMBOBOXCELL_horizontalTextMarginLeft; } textBounds.Height -= verticalTextMarginTop; if (textBounds.Width > 0 && textBounds.Height > 0) { TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); if (!cellEdited && paint) { if (DataGridViewCell.PaintContentForeground(paintParts)) { if ((flags & TextFormatFlags.SingleLine) != 0) { flags |= TextFormatFlags.EndEllipsis; } Color textColor; if (paintPostXPThemes && (drawDropDownButton || drawComboBox)) { textColor = DataGridViewComboBoxCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor); } else { textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; } TextRenderer.DrawText(g, formattedString, cellStyle.Font, textBounds, textColor, flags); } } else if (computeContentBounds) { resultBounds = DataGridViewUtilities.GetTextBounds(textBounds, formattedString, flags, cellStyle); } } } if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts)) { PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText); if (cellEdited) { return Rectangle.Empty; } } } if (computeErrorIconBounds) { if (!String.IsNullOrEmpty(errorText)) { resultBounds = ComputeErrorIconBounds(errorBounds); } else { resultBounds = Rectangle.Empty; } } return resultBounds; }
private void PaintFlat(Graphics g) { TabColorScheme colorScheme=m_ColorScheme; // if(m_Style==eTabStripStyle.Themed) // colorScheme=new TabColorScheme(eTabStripStyle.Flat); if(!colorScheme.TabBackground2.IsEmpty && this.Height>0 && this.Width>0) { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(this.ClientRectangle,colorScheme.TabBackground,colorScheme.TabBackground2,colorScheme.TabBackgroundGradientAngle)) g.FillRectangle(gradient,this.ClientRectangle); } else { using(SolidBrush brush=new SolidBrush(colorScheme.TabBackground)) g.FillRectangle(brush,this.DisplayRectangle); //g.Clear(colorScheme.TabBackground); } if (m_Style != eTabStripStyle.Metro) { if (!colorScheme.TabBorder.IsEmpty) { using (Pen pen = new Pen(colorScheme.TabBorder, 1)) g.DrawRectangle(pen, new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1)); } } // Fill tab background color Rectangle r=this.DisplayRectangle; switch(m_Alignment) { case eTabStripAlignment.Bottom: { r.Height-=3; break; } case eTabStripAlignment.Top: { r.Y+=1; r.Height-=3; break; } } // See how we will draw items TabItem selected=this.SelectedTab; eTextFormat strFormat = eTextFormat.Default | eTextFormat.SingleLine | eTextFormat.EndEllipsis | eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter; int outerBorderAdjustment=(colorScheme.TabBorder.IsEmpty?0:1); // Draw the upper back line if (m_Style != eTabStripStyle.Metro) { switch (m_Alignment) { case eTabStripAlignment.Top: { if (!(this.Parent is TabControl)) g.FillRectangle(new SolidBrush((colorScheme.TabItemSelectedBackground2.IsEmpty ? colorScheme.TabItemSelectedBackground : colorScheme.TabItemSelectedBackground2)), r.X + outerBorderAdjustment, r.Bottom, r.Width - outerBorderAdjustment * 2, this.Height - r.Bottom); else { using (Pen pen = new Pen(colorScheme.TabItemSelectedBorder, 1)) { g.DrawLine(pen, r.X, r.Bottom, r.X, ClientRectangle.Bottom); g.DrawLine(pen, r.Right - 1, r.Bottom, r.Right - 1, ClientRectangle.Bottom); } } g.DrawLine(new Pen(colorScheme.TabItemSelectedBorderLight, 1), r.X + outerBorderAdjustment, r.Bottom, r.Right - 1 - outerBorderAdjustment, r.Bottom); r.Inflate(-4, 0); break; } case eTabStripAlignment.Left: { g.DrawLine(new Pen(colorScheme.TabItemSelectedBorderLight, 1), r.Right - 1, r.Y + outerBorderAdjustment, r.Right - 1, r.Bottom - outerBorderAdjustment); r.Inflate(0, -4); break; } case eTabStripAlignment.Right: { g.DrawLine(new Pen(colorScheme.TabItemSelectedBorderLight, 1), r.X, r.Y + outerBorderAdjustment, r.X, r.Bottom - outerBorderAdjustment); r.Inflate(0, -4); break; } default: { if (!(this.Parent is TabControl)) g.FillRectangle(new SolidBrush(colorScheme.TabItemSelectedBackground), r.X, 0, r.Width, r.Y); else { using (Pen pen = new Pen(colorScheme.TabItemSelectedBorder, 1)) { g.DrawLine(pen, r.X, r.Y, r.X, 0); g.DrawLine(pen, r.Right - 1, r.Y, r.Right - 1, 0); } } g.DrawLine(new Pen(colorScheme.TabItemSelectedBorderLight, 1), r.X, r.Y, r.Right, r.Y); r.Inflate(-4, 0); break; } } } if (this.HasNavigationBox && m_TabSystemBox.Visible) { if(m_Alignment==eTabStripAlignment.Right || m_Alignment==eTabStripAlignment.Left) { if(m_TabSystemBox.DisplayRectangle.Height>0) r.Height-=m_TabSystemBox.DisplayRectangle.Height; else r.Height-=m_TabSystemBox.DefaultWidth; } else { if(m_TabSystemBox.DisplayRectangle.Width>0) r.Width-=m_TabSystemBox.DisplayRectangle.Width; else r.Width-=m_TabSystemBox.DefaultWidth; if(this.IsRightToLeft) r.X += m_TabSystemBox.DefaultWidth; } } if(m_NeedRecalcSize) RecalcSize(g,this.GetTabClientArea(this.DisplayRectangle,false,false)); if(m_Alignment==eTabStripAlignment.Top) r.Height++; Rectangle rClip=r; g.SetClip(r); Rectangle selectedTabRect = Rectangle.Empty; foreach(TabItem tab in m_Tabs) { if(!tab.Visible || !r.IntersectsWith(tab.DisplayRectangle)) continue; if (HasPreRenderTabItem) { RenderTabItemEventArgs re = new RenderTabItemEventArgs(tab, g); InvokePreRenderTabItem(re); if (re.Cancel) continue; } Rectangle tabRect = tab.DisplayRectangle; TabColors tabColors=GetTabColors(tab); if(m_Alignment==eTabStripAlignment.Left || m_Alignment==eTabStripAlignment.Right) { if(tab==selected) { selectedTabRect = tabRect; if(m_Alignment==eTabStripAlignment.Left) { if(tabColors.BackColor2.IsEmpty) { using(SolidBrush brush=new SolidBrush(g.GetNearestColor(tabColors.BackColor))) g.FillRectangle(brush,tabRect); } else { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(tabRect,tabColors.BackColor,tabColors.BackColor2,tabColors.BackColorGradientAngle)) g.FillRectangle(gradient,tabRect); } if (m_Style == eTabStripStyle.Metro) { using (Pen p = new Pen(tabColors.BorderColor, 1)) { g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.Right - 1, tabRect.Y); g.DrawLine(p, tabRect.X, tabRect.Bottom - 1, tabRect.Right - 1, tabRect.Bottom - 1); } using (SolidBrush brush = new SolidBrush(tabColors.TextColor)) g.FillRectangle(brush, new Rectangle(tabRect.X, tabRect.Y, 2, tabRect.Height)); } else { Pen p = new Pen(tabColors.LightBorderColor, 1); g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.Right, tabRect.Y); g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.X, tabRect.Bottom); p.Dispose(); p = new Pen(tabColors.BorderColor, 1); g.DrawLine(p, tabRect.X + 1, tabRect.Bottom, tabRect.Right - 2, tabRect.Bottom); p.Dispose(); } } else { if(tabColors.BackColor2.IsEmpty) { using(SolidBrush brush=new SolidBrush(g.GetNearestColor(tabColors.BackColor))) g.FillRectangle(brush,tabRect.X,tabRect.Y,tabRect.Width,tabRect.Height+1); } else { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(new Rectangle(tabRect.X,tabRect.Y,tabRect.Width,tabRect.Height+1),tabColors.BackColor,tabColors.BackColor2,tabColors.BackColorGradientAngle)) g.FillRectangle(gradient,tabRect.X,tabRect.Y,tabRect.Width,tabRect.Height+1); } if (m_Style == eTabStripStyle.Metro) { using (Pen p = new Pen(tabColors.BorderColor, 1)) { g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.Right - 1, tabRect.Y); g.DrawLine(p, tabRect.X, tabRect.Bottom - 1, tabRect.Right - 1, tabRect.Bottom - 1); } using (SolidBrush brush = new SolidBrush(tabColors.TextColor)) g.FillRectangle(brush, new Rectangle(tabRect.Right - 2, tabRect.Y, 2, tabRect.Height)); } else { Pen p = new Pen(tabColors.LightBorderColor, 1); g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.Right, tabRect.Y); g.DrawLine(p, tabRect.Right - 1, tabRect.Y, tabRect.Right - 1, tabRect.Bottom); p.Dispose(); p = new Pen(tabColors.BorderColor, 1); g.DrawLine(p, tabRect.X, tabRect.Bottom, tabRect.Right - 3, tabRect.Bottom); p.Dispose(); } } } else { if(!tabColors.BackColor.IsEmpty) { if(!tabColors.BackColor2.IsEmpty) { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(tabRect,tabColors.BackColor,tabColors.BackColor2,tabColors.BackColorGradientAngle)) g.FillRectangle(gradient,tabRect); } else { using(SolidBrush brush=new SolidBrush(tabColors.BackColor)) g.FillRectangle(brush,tabRect); } } if(!tabColors.LightBorderColor.IsEmpty) { if(m_Alignment==eTabStripAlignment.Left) { using(Pen p=new Pen(tabColors.LightBorderColor,1)) { g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.Right,tabRect.Y); g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.X,tabRect.Bottom); } } else { using(Pen p=new Pen(tabColors.LightBorderColor,1)) { g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.Right,tabRect.Y); g.DrawLine(p,tabRect.Right-1,tabRect.Y,tabRect.Right-1,tabRect.Bottom); } } } if(!tabColors.BorderColor.IsEmpty) { if(m_Alignment==eTabStripAlignment.Left) { using(Pen p=new Pen(tabColors.BorderColor,1)) { g.DrawLine(p,tabRect.X+1,tabRect.Bottom,tabRect.Right-2,tabRect.Bottom); g.DrawLine(p,tabRect.Right-1,tabRect.Bottom,tabRect.Right-1,tabRect.Y+1); } } else { using(Pen p=new Pen(tabColors.BorderColor,1)) { g.DrawLine(p,tabRect.X,tabRect.Y+1,tabRect.X,tabRect.Bottom); g.DrawLine(p,tabRect.X+1,tabRect.Bottom,tabRect.Right-2,tabRect.Bottom); } } } } if (m_CloseButtonOnTabs && tab.CloseButtonVisible) tab.CloseButtonBounds = PaintTabItemCloseButton(g, true, tab.CloseButtonMouseOver, tab == m_HotTab || tab == this.SelectedTab, ref tabRect); else tab.CloseButtonBounds = Rectangle.Empty; Image tabImage=tab.GetImage(); Icon icon=tab.Icon; if(tabImage!=null && tabImage.Width+4<=tabRect.Width || icon!=null && tab.IconSize.Width+4<=tabRect.Width) { if(icon!=null) { Rectangle rIcon=new Rectangle(tabRect.X+(tabRect.Width-tab.IconSize.Width)/2,tabRect.Y+4,tab.IconSize.Width,tab.IconSize.Height); if(rClip.Contains(rIcon)) g.DrawIcon(icon,rIcon); tabRect.Y+=(tab.IconSize.Height+2); tabRect.Height-=(tab.IconSize.Height+2); } else if(tabImage!=null) { g.DrawImage(tabImage,tabRect.X+(tabRect.Width-tabImage.Width)/2,tabRect.Y+4,tabImage.Width,tabImage.Height); tabRect.Y+=(tabImage.Height+2); tabRect.Height-=(tabImage.Height+2); } tabRect.Inflate(0,-1); tabRect.Height-=4; tabRect.Y+=3; } else { tabRect.Y+=2; tabRect.Height-=2; } g.RotateTransform(90); if(!m_DisplaySelectedTextOnly || tab==m_SelectedTab) { Font font=this.Font; if(tab==selected && m_SelectedTabFont!=null) font=m_SelectedTabFont; Rectangle rText=new Rectangle(tabRect.Top,-tabRect.Right,tabRect.Height,tabRect.Width); if(rText.Height>MIN_TEXT_WIDTH) { TextDrawing.DrawStringLegacy(g,tab.Text,font,tabColors.TextColor,rText,strFormat); } if(m_ShowFocusRectangle && this.Focused && tab==m_SelectedTab) ControlPaint.DrawFocusRectangle(g,GetFocusRectangle(rText)); g.ResetTransform(); } // Draw separator if(tab!=selected) { g.DrawLine(new Pen(colorScheme.TabItemSeparator,1),tab.DisplayRectangle.X+1,tab.DisplayRectangle.Bottom,tab.DisplayRectangle.Right-4,tab.DisplayRectangle.Bottom); if(!colorScheme.TabItemSeparatorShade.IsEmpty) g.DrawLine(new Pen(colorScheme.TabItemSeparatorShade,1),tab.DisplayRectangle.X+1+1,tab.DisplayRectangle.Bottom+1,tab.DisplayRectangle.Right-4+1,tab.DisplayRectangle.Bottom+1); } } else { if(tab==selected) { selectedTabRect = tabRect; if(m_Alignment==eTabStripAlignment.Bottom) { if(tabColors.BackColor2.IsEmpty) { using(SolidBrush brush=new SolidBrush(g.GetNearestColor(tabColors.BackColor))) g.FillRectangle(brush,tabRect); } else { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(tabRect,tabColors.BackColor,tabColors.BackColor2,tabColors.BackColorGradientAngle)) g.FillRectangle(gradient,tabRect); } if (m_Style == eTabStripStyle.Metro) { using (Pen p = new Pen(tabColors.BorderColor, 1)) { g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.X, tabRect.Bottom - 1); g.DrawLine(p, tabRect.Right - 1, tabRect.Y, tabRect.Right - 1, tabRect.Bottom - 1); } using (SolidBrush brush = new SolidBrush(tabColors.TextColor)) g.FillRectangle(brush, new Rectangle(tabRect.X, tabRect.Bottom - 2, tabRect.Width, 2)); } else { using (Pen p = new Pen(tabColors.LightBorderColor, 1)) g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.X, tabRect.Bottom); using (Pen p = new Pen(tabColors.BorderColor, 1)) { g.DrawLine(p, tabRect.X + 1, tabRect.Bottom, tabRect.Right, tabRect.Bottom); g.DrawLine(p, tabRect.Right, tabRect.Y, tabRect.Right, tabRect.Bottom); } } } else { if(tabColors.BackColor2.IsEmpty) { using(SolidBrush brush=new SolidBrush(g.GetNearestColor(tabColors.BackColor))) g.FillRectangle(brush,tabRect.X,tabRect.Y,tabRect.Width,tabRect.Height+1); } else { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(new Rectangle(tabRect.X,tabRect.Y,tabRect.Width,tabRect.Height+1),tabColors.BackColor,tabColors.BackColor2,tabColors.BackColorGradientAngle)) g.FillRectangle(gradient,tabRect.X,tabRect.Y,tabRect.Width,tabRect.Height+1); } if (m_Style == eTabStripStyle.Metro) { using (Pen p = new Pen(tabColors.BorderColor, 1)) { g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.X, tabRect.Bottom); g.DrawLine(p, tabRect.Right - 1, tabRect.Y, tabRect.Right - 1, tabRect.Bottom); } using (SolidBrush brush = new SolidBrush(tabColors.TextColor)) g.FillRectangle(brush, new Rectangle(tabRect.X, tabRect.Y, tabRect.Width, 2)); } else { using (Pen p = new Pen(tabColors.LightBorderColor, 1)) { g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.X, tabRect.Bottom); g.DrawLine(p, tabRect.X, tabRect.Y, tabRect.Right, tabRect.Y); } using (Pen p = new Pen(tabColors.BorderColor, 1)) g.DrawLine(p, tabRect.Right, tabRect.Y, tabRect.Right, tabRect.Bottom); } } } else { if(!tabColors.BackColor.IsEmpty) { Rectangle rBack=tabRect; rBack.Width--; rBack.X++; rBack.Height--; rBack.Y++; if(!tabColors.BackColor2.IsEmpty) { using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(tabRect,tabColors.BackColor,tabColors.BackColor2,tabColors.BackColorGradientAngle)) g.FillRectangle(gradient,rBack); } else { using(SolidBrush brush=new SolidBrush(tabColors.BackColor)) g.FillRectangle(brush,rBack); } } if(!tabColors.LightBorderColor.IsEmpty) { if(m_Alignment==eTabStripAlignment.Bottom) { using(Pen p=new Pen(tabColors.LightBorderColor,1)) { g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.Right,tabRect.Y); g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.X,tabRect.Bottom); } } else { using(Pen p=new Pen(tabColors.LightBorderColor,1)) { g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.X,tabRect.Bottom); g.DrawLine(p,tabRect.X,tabRect.Y,tabRect.Right,tabRect.Y); } } } if(!tabColors.BorderColor.IsEmpty) { if(m_Alignment==eTabStripAlignment.Bottom) { using(Pen p=new Pen(tabColors.BorderColor,1)) { g.DrawLine(p,tabRect.X+1,tabRect.Bottom,tabRect.Right,tabRect.Bottom); g.DrawLine(p,tabRect.Right,tabRect.Y,tabRect.Right,tabRect.Bottom); } } else { using(Pen p=new Pen(tabColors.BorderColor,1)) { g.DrawLine(p,tabRect.Right-1,tabRect.Y,tabRect.Right-1,tabRect.Bottom); g.DrawLine(p,tabRect.X,tabRect.Bottom,tabRect.Right,tabRect.Bottom); } } } } if(m_Alignment==eTabStripAlignment.Top) tabRect.Offset(0,1); if (m_CloseButtonOnTabs && tab.CloseButtonVisible) tab.CloseButtonBounds = PaintTabItemCloseButton(g, false, tab.CloseButtonMouseOver, tab == m_HotTab || tab == this.SelectedTab, ref tabRect); else tab.CloseButtonBounds = Rectangle.Empty; Image tabImage=tab.GetImage(); Icon icon=tab.Icon; if(tabImage!=null && tabImage.Width+4<tabRect.Width || icon!=null && tab.IconSize.Width+4<tabRect.Width) { if(icon!=null) { Rectangle rIcon=new Rectangle(tabRect.X+4,tabRect.Y+(tabRect.Height-tab.IconSize.Height)/2,tab.IconSize.Width,tab.IconSize.Height); if(rClip.Contains(rIcon)) g.DrawIcon(icon,rIcon); tabRect.X+=(tab.IconSize.Width+2); tabRect.Width-=(tab.IconSize.Width+2); } else if(tabImage!=null) { g.DrawImage(tabImage,tabRect.X+4,tabRect.Y+(tabRect.Height-tabImage.Height)/2,tabImage.Width,tabImage.Height); tabRect.X+=(tabImage.Width+2); tabRect.Width-=(tabImage.Width+2); } tabRect.Inflate(0,-1); tabRect.Width-=4; tabRect.X+=3; } else { tabRect.X+=2; tabRect.Width-=2; } if(!m_DisplaySelectedTextOnly || tab==m_SelectedTab) { Font font=this.Font; if(tab==selected && m_SelectedTabFont!=null) font=m_SelectedTabFont; if(tabRect.Width>MIN_TEXT_WIDTH) { TextDrawing.DrawString(g,tab.Text,font,tabColors.TextColor,tabRect,strFormat); } if(m_ShowFocusRectangle && this.Focused && tab==m_SelectedTab) ControlPaint.DrawFocusRectangle(g,GetFocusRectangle(tabRect)); } if(tab!=selected) { Rectangle rect = tab.DisplayRectangle; if (this.IsRightToLeft) rect.Width -= 2; using(Pen p=new Pen(colorScheme.TabItemSeparator,1)) g.DrawLine(p,rect.Right,rect.Y+2,rect.Right,rect.Bottom-4); if(!colorScheme.TabItemSeparatorShade.IsEmpty) { using(Pen p=new Pen(colorScheme.TabItemSeparatorShade,1)) g.DrawLine(p,rect.Right+1,rect.Y+2+1,rect.Right+1,rect.Bottom-4+1); } } } if (HasPostRenderTabItem) { RenderTabItemEventArgs re = new RenderTabItemEventArgs(tab, g); InvokePostRenderTabItem(re); } } g.ResetClip(); if (m_Style == eTabStripStyle.Metro && !selectedTabRect.IsEmpty && !colorScheme.TabBorder.IsEmpty) { if (m_Alignment == eTabStripAlignment.Top) { using (Pen pen = new Pen(colorScheme.TabBorder, 1)) { g.DrawLine(pen, ClientRectangle.X, ClientRectangle.Bottom - 1, selectedTabRect.X, ClientRectangle.Bottom - 1); g.DrawLine(pen, selectedTabRect.Right - 1, ClientRectangle.Bottom - 1, ClientRectangle.Right - 1, ClientRectangle.Bottom - 1); } } else if (m_Alignment == eTabStripAlignment.Bottom) { using (Pen pen = new Pen(colorScheme.TabBorder, 1)) { g.DrawLine(pen, ClientRectangle.X, ClientRectangle.Y, selectedTabRect.X, ClientRectangle.Y); g.DrawLine(pen, selectedTabRect.Right - 1, ClientRectangle.Y, ClientRectangle.Right - 1, ClientRectangle.Y); } } else if (m_Alignment == eTabStripAlignment.Left) { using (Pen pen = new Pen(colorScheme.TabBorder, 1)) { g.DrawLine(pen, ClientRectangle.Right - 1, ClientRectangle.Y, ClientRectangle.Right - 1, selectedTabRect.Y); g.DrawLine(pen, ClientRectangle.Right - 1, selectedTabRect.Bottom - 1, ClientRectangle.Right - 1, ClientRectangle.Bottom - 1); } } else if (m_Alignment == eTabStripAlignment.Right) { using (Pen pen = new Pen(colorScheme.TabBorder, 1)) { g.DrawLine(pen, ClientRectangle.X, ClientRectangle.Y, ClientRectangle.X, selectedTabRect.Y); g.DrawLine(pen, ClientRectangle.X, selectedTabRect.Bottom - 1, ClientRectangle.X, ClientRectangle.Bottom - 1); } } } if(this.HasNavigationBox && m_TabSystemBox.Visible) { g.SetClip(m_TabSystemBox.DisplayRectangle); m_TabSystemBox.Paint(g); g.ResetClip(); } }