public static WindowsGraphics CreateMeasurementWindowsGraphics() { DeviceContext dc = DeviceContext.FromCompatibleDC(IntPtr.Zero); WindowsGraphics wg = new WindowsGraphics(dc); wg.disposeDc = true; // we create it, we dispose it. return wg; }
/// GetTextMargins - checks to see if we have cached information about the current font, /// returns info about it. /// An MRU of Font margins was considered, but seems like overhead. internal static IntNativeMethods.DRAWTEXTPARAMS GetTextMargins(WindowsGraphics wg, WindowsFont font) { // PERF: operate on a local reference rather than party directly on the thread static one. CachedInfo currentCachedInfo = cachedMeasurementDCInfo; if (currentCachedInfo != null && currentCachedInfo.LeftTextMargin >0 && currentCachedInfo.RightTextMargin >0 && font == currentCachedInfo.LastUsedFont) { // we have to return clones as DrawTextEx will modify this struct return new IntNativeMethods.DRAWTEXTPARAMS(currentCachedInfo.LeftTextMargin,currentCachedInfo.RightTextMargin); } else if (currentCachedInfo == null) { currentCachedInfo = new CachedInfo(); cachedMeasurementDCInfo = currentCachedInfo; } IntNativeMethods.DRAWTEXTPARAMS drawTextParams = wg.GetTextMargins(font); currentCachedInfo.LeftTextMargin = drawTextParams.iLeftMargin; currentCachedInfo.RightTextMargin = drawTextParams.iRightMargin; // returning a copy here to be consistent with the return value from the cache. return new IntNativeMethods.DRAWTEXTPARAMS(currentCachedInfo.LeftTextMargin,currentCachedInfo.RightTextMargin); }
/// <devdoc> /// Creates a WindowsGraphics object from a Graphics object. Clipping and coordinate transforms /// are preserved. /// /// Notes: /// - The passed Graphics object cannot be used until the WindowsGraphics is disposed /// since it borrows the hdc from the Graphics object locking it. /// - Changes to the hdc using the WindowsGraphics object are not preserved into the Graphics object; /// the hdc is returned to the Graphics object intact. /// /// Some background about how Graphics uses the internal hdc when created from an existing one /// (mail from GillesK from GDI+ team): /// User has an HDC with a particular state: /// Graphics object gets created based on that HDC. We query the HDC for its state and apply it to the Graphics. /// At this stage, we do a SaveHDC and clear everything out of it. /// User calls GetHdc. We restore the HDC to the state it was in and give it to the user. /// User calls ReleaseHdc, we save the current state of the HDC and clear everything /// (so that the graphics state gets applied next time we use it). /// Next time the user calls GetHdc we give him back the state after the second ReleaseHdc. /// (But the state changes between the GetHdc and ReleaseHdc are not applied to the Graphics). /// Please note that this only applies the HDC created graphics, for Bitmap derived graphics, GetHdc creates a new DIBSection and /// things get a lot more complicated. /// </devdoc> public static WindowsGraphics FromGraphics(Graphics g) { ApplyGraphicsProperties properties = ApplyGraphicsProperties.All; return(WindowsGraphics.FromGraphics(g, properties)); }
public override void execute(WindowsGraphics underlying) { underlying.setColor(color); underlying.setAlpha(alpha); underlying.fillPolygon(p1, p2); }
private void DrawGroupBox(PaintEventArgs e) { Graphics graphics = e.Graphics; Rectangle textRectangle = ClientRectangle; // Max text bounding box passed to drawing methods to support RTL. int textOffset = 8; // Offset from the left bound. Color backColor = DisabledColor; Pen light = new Pen(ControlPaint.Light(backColor, 1.0f)); Pen dark = new Pen(ControlPaint.Dark(backColor, 0f)); Size textSize; textRectangle.X += textOffset; textRectangle.Width -= 2 * textOffset; try { if (UseCompatibleTextRendering) { using (Brush textBrush = new SolidBrush(ForeColor)){ using (StringFormat format = new StringFormat()){ format.HotkeyPrefix = ShowKeyboardCues ? System.Drawing.Text.HotkeyPrefix.Show : System.Drawing.Text.HotkeyPrefix.Hide; // Adjust string format for Rtl controls if (RightToLeft == RightToLeft.Yes) { format.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } textSize = Size.Ceiling(graphics.MeasureString(Text, Font, textRectangle.Width, format)); if (Enabled) { graphics.DrawString(Text, Font, textBrush, textRectangle, format); } else { ControlPaint.DrawStringDisabled(graphics, Text, Font, backColor, textRectangle, format); } } } } else { using (WindowsGraphics wg = WindowsGraphics.FromGraphics(graphics)){ IntTextFormatFlags flags = IntTextFormatFlags.WordBreak | IntTextFormatFlags.TextBoxControl; if (!ShowKeyboardCues) { flags |= IntTextFormatFlags.HidePrefix; } if (RightToLeft == RightToLeft.Yes) { flags |= IntTextFormatFlags.RightToLeft; flags |= IntTextFormatFlags.Right; } using (WindowsFont wfont = WindowsGraphicsCacheManager.GetWindowsFont(this.Font)) { textSize = wg.MeasureText(Text, wfont, new Size(textRectangle.Width, int.MaxValue), flags); if (Enabled) { wg.DrawText(Text, wfont, textRectangle, ForeColor, flags); } else { ControlPaint.DrawStringDisabled(wg, Text, Font, backColor, textRectangle, ((TextFormatFlags)flags)); } } } } int textLeft = textOffset; // Left side of binding box (independent on RTL). if (RightToLeft == RightToLeft.Yes) { textLeft += textRectangle.Width - textSize.Width; } // Math.Min to assure we paint at least a small line. int textRight = Math.Min(textLeft + textSize.Width, Width - 6); int boxTop = FontHeight / 2; // left graphics.DrawLine(light, 1, boxTop, 1, Height - 1); graphics.DrawLine(dark, 0, boxTop, 0, Height - 2); // bottom graphics.DrawLine(light, 0, Height - 1, Width, Height - 1); graphics.DrawLine(dark, 0, Height - 2, Width - 1, Height - 2); // top-left graphics.DrawLine(dark, 0, boxTop - 1, textLeft, boxTop - 1); graphics.DrawLine(light, 1, boxTop, textLeft, boxTop); // top-right graphics.DrawLine(dark, textRight, boxTop - 1, Width - 2, boxTop - 1); graphics.DrawLine(light, textRight, boxTop, Width - 1, boxTop); // right graphics.DrawLine(light, Width - 1, boxTop - 1, Width - 1, Height - 1); graphics.DrawLine(dark, Width - 2, boxTop, Width - 2, Height - 2); } finally { light.Dispose(); dark.Dispose(); } }
/// IsMeasurementDC /// Returns whether the IDeviceContext passed in is our static MeasurementDC. /// If it is, we know a bit more information about it. internal static bool IsMeasurementDC(DeviceContext dc) { WindowsGraphics sharedGraphics = WindowsGraphicsCacheManager.GetCurrentMeasurementGraphics(); return(sharedGraphics != null && sharedGraphics.DeviceContext != null && sharedGraphics.DeviceContext.Hdc == dc.Hdc); }
public override void execute(WindowsGraphics underlying) { underlying.setColor(color); underlying.setAlpha(alpha); underlying.drawPath(path, stroke); }
protected override void OnPaint(PaintEventArgs e) { Color nearestColor; this.Animate(); Rectangle r = LayoutUtils.DeflateRect(base.ClientRectangle, base.Padding); ImageAnimator.UpdateFrames(); System.Drawing.Image image = this.Image; if (image != null) { this.DrawImage(e.Graphics, image, r, base.RtlTranslateAlignment(this.ImageAlign)); } IntPtr hdc = e.Graphics.GetHdc(); try { using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc)) { nearestColor = graphics.GetNearestColor(base.Enabled ? this.ForeColor : base.DisabledColor); } } finally { e.Graphics.ReleaseHdc(); } if (this.AutoEllipsis) { Rectangle clientRectangle = base.ClientRectangle; Size preferredSize = this.GetPreferredSize(new Size(clientRectangle.Width, clientRectangle.Height)); this.showToolTip = (clientRectangle.Width < preferredSize.Width) || (clientRectangle.Height < preferredSize.Height); } else { this.showToolTip = false; } if (this.UseCompatibleTextRendering) { using (StringFormat format = this.CreateStringFormat()) { if (base.Enabled) { using (Brush brush = new SolidBrush(nearestColor)) { e.Graphics.DrawString(this.Text, this.Font, brush, r, format); goto Label_01BF; } } ControlPaint.DrawStringDisabled(e.Graphics, this.Text, this.Font, nearestColor, r, format); goto Label_01BF; } } TextFormatFlags flags = this.CreateTextFormatFlags(); if (base.Enabled) { TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, nearestColor, flags); } else { Color foreColor = TextRenderer.DisabledTextColor(this.BackColor); TextRenderer.DrawText(e.Graphics, this.Text, this.Font, r, foreColor, flags); } Label_01BF: base.OnPaint(e); }
/// <include file='doc\WindowsGraphics.uex' path='docs/doc[@for="WindowsGraphics.FromHwnd"]/*' /> public static WindowsGraphics FromHwnd(IntPtr hWnd) { DeviceContext dc = DeviceContext.FromHwnd( hWnd ); WindowsGraphics wg = new WindowsGraphics( dc ); wg.disposeDc = true; // we create it, we dispose it. return wg; }
public override void execute(WindowsGraphics underlying) { underlying.fillLinearGradient(startColor, endColor, x, y, width, height, horizontal); }
/// <devdoc> /// Dispose of cached memory dc. /// </devdoc> public static void ResetMeasurementGraphics() { if( measurementGraphics != null ) { #if TRACK_HDC //Debug.WriteLine( DbgUtil.StackTraceToStr(string.Format("Disposing measurement DC and WG for thread: [0x{0:x8}]", Thread.CurrentThread.ManagedThreadId))); Debug.WriteLine( DbgUtil.StackTraceToStr("Disposing measurement DC and WG")); #endif measurementGraphics.Dispose(); measurementGraphics = null; } }
public WindowsGraphicsWrapper(IDeviceContext deviceContext, TextFormatFlags flags) { if (deviceContext is Graphics) { ApplyGraphicsProperties properties = ApplyGraphicsProperties.None; if ((flags & TextFormatFlags.PreserveGraphicsClipping) != 0) { properties |= ApplyGraphicsProperties.Clipping; } if ((flags & TextFormatFlags.PreserveGraphicsTranslateTransform) != 0) { properties |= ApplyGraphicsProperties.TranslateTransform; } // Create the WindowsGraphics from the Grahpics object only if Graphics properties need // to be reapplied to the DC wrapped by the WindowsGraphics. if (properties != ApplyGraphicsProperties.None) { try { _windowsGraphics = WindowsGraphics.FromGraphics(deviceContext as Graphics, properties); } catch { GC.SuppressFinalize(this); throw; } } } else { // If passed-in IDeviceContext object is a WindowsGraphics we can use it directly. _windowsGraphics = deviceContext as WindowsGraphics; if (_windowsGraphics != null) { // In this case we cache the idc to compare it against the wg in the Dispose method to avoid // disposing of the wg. _deviceContext = deviceContext; } } if (_windowsGraphics == null) { // The IDeviceContext object is not a WindowsGraphics, or it is a custom IDeviceContext, or // it is a Graphics object but we did not need to re-apply Graphics propertiesto the hdc. // So create the WindowsGraphics from the hdc directly. // Cache the IDC so the hdc can be released ons dispose. try { _deviceContext = deviceContext; _windowsGraphics = WindowsGraphics.FromHdc((Gdi32.HDC)deviceContext.GetHdc()); } catch { SuppressFinalize(); deviceContext.ReleaseHdc(); throw; } } // Set text padding on the WindowsGraphics (if any). if ((flags & TextFormatFlags.LeftAndRightPadding) != 0) { _windowsGraphics.TextPadding = TextPaddingOptions.LeftAndRightPadding; } else if ((flags & TextFormatFlags.NoPadding) != 0) { _windowsGraphics.TextPadding = TextPaddingOptions.NoPadding; } // else wg.TextPadding = TextPaddingOptions.GlyphOverhangPadding - the default value. }
public override void execute(WindowsGraphics underlying) { underlying.setAlpha(alpha); underlying.setColor(color); underlying.fillPath(path); }
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 empty; Point currentCellAddress = base.DataGridView.CurrentCellAddress; bool flag = (elementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None; bool flag2 = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex); string text = formattedValue as string; SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor); SolidBrush brush2 = base.DataGridView.GetCachedBrush(flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor); if (paint && DataGridViewCell.PaintBorder(paintParts)) { this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } Rectangle rect = cellBounds; Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle); rect.Offset(rectangle3.X, rectangle3.Y); rect.Width -= rectangle3.Right; rect.Height -= rectangle3.Bottom; if ((rect.Height <= 0) || (rect.Width <= 0)) { return(Rectangle.Empty); } if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff)) { g.FillRectangle(cachedBrush, rect); } if (cellStyle.Padding != Padding.Empty) { if (base.DataGridView.RightToLeftInternal) { rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top); } else { rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top); } rect.Width -= cellStyle.Padding.Horizontal; rect.Height -= cellStyle.Padding.Vertical; } Rectangle cellValueBounds = rect; if (((rect.Height <= 0) || (rect.Width <= 0)) || (!paint && !computeContentBounds)) { if (computeErrorIconBounds) { if (!string.IsNullOrEmpty(errorText)) { empty = base.ComputeErrorIconBounds(cellValueBounds); } else { empty = Rectangle.Empty; } } else { empty = Rectangle.Empty; } goto Label_06AD; } if ((this.FlatStyle == System.Windows.Forms.FlatStyle.Standard) || (this.FlatStyle == System.Windows.Forms.FlatStyle.System)) { if (base.DataGridView.ApplyVisualStylesToInnerCells) { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { PushButtonState normal = PushButtonState.Normal; if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { normal = PushButtonState.Pressed; } else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { normal = PushButtonState.Hot; } if ((DataGridViewCell.PaintFocus(paintParts) && flag2) && (base.DataGridView.ShowFocusCues && base.DataGridView.Focused)) { normal |= PushButtonState.Default; } DataGridViewButtonCellRenderer.DrawButton(g, rect, (int)normal); } empty = rect; rect = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, rect); } else { if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { ControlPaint.DrawBorder(g, rect, SystemColors.Control, (this.ButtonState == System.Windows.Forms.ButtonState.Normal) ? ButtonBorderStyle.Outset : ButtonBorderStyle.Inset); } empty = rect; rect.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height); } goto Label_06AD; } if (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat) { rect.Inflate(-1, -1); if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { ButtonBaseAdapter.ColorData data2 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, rect, data2.options.highContrast ? data2.windowText : data2.windowFrame, true); ControlPaint.DrawBorder(g, rect, data2.options.highContrast ? data2.windowText : data2.buttonShadow, ButtonBorderStyle.Solid); } else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, rect, colors.options.highContrast ? colors.windowText : colors.buttonShadow, false); ButtonBaseAdapter.Draw3DLiteBorder(g, rect, colors, true); } else { ButtonBaseAdapter.ColorData data4 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); ButtonBaseAdapter.DrawDefaultBorder(g, rect, data4.options.highContrast ? data4.windowText : data4.buttonShadow, false); ButtonBaseAdapter.DrawFlatBorder(g, rect, data4.options.highContrast ? data4.windowText : data4.buttonShadow); } } empty = rect; goto Label_06AD; } rect.Inflate(-1, -1); if (paint && DataGridViewCell.PaintContentBackground(paintParts)) { ButtonBaseAdapter.DrawDefaultBorder(g, rect, brush2.Color, true); if (cachedBrush.Color.A == 0xff) { if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) { ButtonBaseAdapter.ColorData data = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); IntPtr hdc = g.GetHdc(); try { using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc)) { WindowsBrush brush3; if (data.options.highContrast) { brush3 = new WindowsSolidBrush(graphics.DeviceContext, data.buttonShadow); } else { brush3 = new WindowsSolidBrush(graphics.DeviceContext, data.lowHighlight); } try { ButtonBaseAdapter.PaintButtonBackground(graphics, rect, brush3); } finally { brush3.Dispose(); } } goto Label_04CF; } finally { g.ReleaseHdc(); } } if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds) { IntPtr hDc = g.GetHdc(); try { using (WindowsGraphics graphics2 = WindowsGraphics.FromHdc(hDc)) { Color controlDark = SystemColors.ControlDark; using (WindowsBrush brush4 = new WindowsSolidBrush(graphics2.DeviceContext, controlDark)) { ButtonBaseAdapter.PaintButtonBackground(graphics2, rect, brush4); } } } finally { g.ReleaseHdc(); } } } } Label_04CF: empty = rect; Label_06AD: if (((paint && DataGridViewCell.PaintFocus(paintParts)) && (flag2 && base.DataGridView.ShowFocusCues)) && ((base.DataGridView.Focused && (rect.Width > ((2 * SystemInformation.Border3DSize.Width) + 1))) && (rect.Height > ((2 * SystemInformation.Border3DSize.Height) + 1)))) { if ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard)) { ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(rect, -1, -1), Color.Empty, SystemColors.Control); } else if (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) { if (((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) || ((base.DataGridView.CurrentCellAddress.Y == rowIndex) && (base.DataGridView.CurrentCellAddress.X == base.ColumnIndex))) { ButtonBaseAdapter.ColorData data5 = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate(); string str2 = (text != null) ? text : string.Empty; ButtonBaseAdapter.LayoutOptions options = ButtonFlatAdapter.PaintFlatLayout(g, true, SystemInformation.HighContrast, 1, rect, Padding.Empty, false, cellStyle.Font, str2, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options.everettButtonCompat = false; ButtonBaseAdapter.LayoutData data6 = options.Layout(); ButtonBaseAdapter.DrawFlatFocus(g, data6.focus, data5.options.highContrast ? data5.windowText : data5.constrastButtonShadow); } } else if (((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) || ((base.DataGridView.CurrentCellAddress.Y == rowIndex) && (base.DataGridView.CurrentCellAddress.X == base.ColumnIndex))) { bool up = this.ButtonState == System.Windows.Forms.ButtonState.Normal; string str3 = (text != null) ? text : string.Empty; ButtonBaseAdapter.LayoutOptions options2 = ButtonPopupAdapter.PaintPopupLayout(g, up, SystemInformation.HighContrast ? 2 : 1, rect, Padding.Empty, false, cellStyle.Font, str3, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft); options2.everettButtonCompat = false; ButtonBaseAdapter.LayoutData data7 = options2.Layout(); ControlPaint.DrawFocusRectangle(g, data7.focus, cellStyle.ForeColor, cellStyle.BackColor); } } if (((text != null) && paint) && DataGridViewCell.PaintContentForeground(paintParts)) { rect.Offset(2, 1); rect.Width -= 4; rect.Height -= 2; if ((((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Popup)) { rect.Offset(1, 1); rect.Width--; rect.Height--; } if ((rect.Width > 0) && (rect.Height > 0)) { Color color; if (base.DataGridView.ApplyVisualStylesToInnerCells && ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard))) { color = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetColor(ColorProperty.TextColor); } else { color = brush2.Color; } TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode); TextRenderer.DrawText(g, text, cellStyle.Font, rect, color, flags); } } if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts)) { base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText); } return(empty); }
public override void execute(WindowsGraphics underlying) { underlying.fillRadialGradient(startColor, endColor, x, y, width, height); }
public static WindowsGraphics FromHdc(IntPtr hDc) { Debug.Assert( hDc != IntPtr.Zero, "null hDc" ); DeviceContext dc = DeviceContext.FromHdc(hDc); WindowsGraphics wg = new WindowsGraphics( dc ); wg.disposeDc = true; // we create it, we dispose it. return wg; }
public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties properties) { Debug.Assert(g != null, "null Graphics object."); //Debug.Assert( properties != ApplyGraphicsProperties.None, "Consider using other WindowsGraphics constructor if not preserving Graphics properties." ); WindowsRegion wr = null; float[] elements = null; Region clipRgn = null; Matrix worldTransf = null; if ((properties & ApplyGraphicsProperties.TranslateTransform) != 0 || (properties & ApplyGraphicsProperties.Clipping) != 0) { object[] data = g.GetContextInfo() as object[]; if (data != null && data.Length == 2) { clipRgn = data[0] as Region; worldTransf = data[1] as Matrix; } if (worldTransf != null) { if ((properties & ApplyGraphicsProperties.TranslateTransform) != 0) { elements = worldTransf.Elements; } worldTransf.Dispose(); } if (clipRgn != null) { if ((properties & ApplyGraphicsProperties.Clipping) != 0) { // We have to create the WindowsRegion and dipose the Region object before locking the Graphics object, // in case of an unlikely exception before releasing the WindowsRegion, the finalizer will do it for us. // (no try-finally block since this method is used frequently - perf). // See VSWhidbey#383762 // If the Graphics.Clip has not been set (Region.IsInfinite) we don't need to apply it to the DC. if (!clipRgn.IsInfinite(g)) { wr = WindowsRegion.FromRegion(clipRgn, g); // WindowsRegion will take ownership of the hRegion. } } clipRgn.Dispose(); // Disposing the Region object doesn't destroy the hRegion. } } WindowsGraphics wg = WindowsGraphics.FromHdc(g.GetHdc()); // This locks the Graphics object. wg.graphics = g; // Apply transform and clip if (wr != null) { using (wr) { // If the Graphics object was created from a native DC the actual clipping region is the intersection // beteween the original DC clip region and the GDI+ one - for display Graphics it is the same as // Graphics.VisibleClipBounds. See VSW#490404. wg.DeviceContext.IntersectClip(wr); } } if (elements != null) { // elements (XFORM) = [eM11, eM12, eM21, eM22, eDx, eDy], eDx/eDy specify the translation offset. wg.DeviceContext.TranslateTransform((int)elements[4], (int)elements[5]); } return(wg); }