public WindowsGraphicsWrapper( IDeviceContext idc, TextFormatFlags flags) { if( idc 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 ) { this.wg = WindowsGraphics.FromGraphics( idc as Graphics, properties); } } else { // If passed-in IDeviceContext object is a WindowsGraphics we can use it directly. this.wg = idc as WindowsGraphics; if( this.wg != null ) { // In this case we cache the idc to compare it against the wg in the Dispose method to avoid // disposing of the wg. this.idc = idc; } } if( this.wg == 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 on dispose. this.idc = idc; this.wg = WindowsGraphics.FromHdc( idc.GetHdc() ); } // Set text padding on the WindowsGraphics (if any). if( (flags & TextFormatFlags.LeftAndRightPadding) != 0 ) { wg.TextPadding = TextPaddingOptions.LeftAndRightPadding; } else if ((flags & TextFormatFlags.NoPadding) != 0 ) { wg.TextPadding = TextPaddingOptions.NoPadding; } // else wg.TextPadding = TextPaddingOptions.GlyphOverhangPadding - the default value. }
public void Dispose(bool disposing) { if (this.wg != null) { if (this.wg != this.idc) { this.wg.Dispose(); if (this.idc != null) { this.idc.ReleaseHdc(); } } this.idc = null; this.wg = null; } }
internal static IntNativeMethods.DRAWTEXTPARAMS GetTextMargins(WindowsGraphics wg, WindowsFont font) { CachedInfo cachedMeasurementDCInfo = MeasurementDCInfo.cachedMeasurementDCInfo; if (((cachedMeasurementDCInfo == null) || (cachedMeasurementDCInfo.LeftTextMargin <= 0)) || ((cachedMeasurementDCInfo.RightTextMargin <= 0) || (font != cachedMeasurementDCInfo.LastUsedFont))) { if (cachedMeasurementDCInfo == null) { cachedMeasurementDCInfo = new CachedInfo(); MeasurementDCInfo.cachedMeasurementDCInfo = cachedMeasurementDCInfo; } IntNativeMethods.DRAWTEXTPARAMS textMargins = wg.GetTextMargins(font); cachedMeasurementDCInfo.LeftTextMargin = textMargins.iLeftMargin; cachedMeasurementDCInfo.RightTextMargin = textMargins.iRightMargin; } return new IntNativeMethods.DRAWTEXTPARAMS(cachedMeasurementDCInfo.LeftTextMargin, cachedMeasurementDCInfo.RightTextMargin); }
private static void DrawAndFillEllipse(WindowsGraphics wg, WindowsPen borderPen, WindowsBrush fieldBrush, Rectangle bounds) { if (wg != null) { wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y), new Point(bounds.X + 8, bounds.Y)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X, bounds.Y + 4), new Point(bounds.X, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10)); } }
public WindowsGraphicsWrapper(IDeviceContext idc, TextFormatFlags flags) { if (idc is Graphics) { ApplyGraphicsProperties none = ApplyGraphicsProperties.None; if ((flags & TextFormatFlags.PreserveGraphicsClipping) != TextFormatFlags.Default) { none |= ApplyGraphicsProperties.Clipping; } if ((flags & TextFormatFlags.PreserveGraphicsTranslateTransform) != TextFormatFlags.Default) { none |= ApplyGraphicsProperties.TranslateTransform; } if (none != ApplyGraphicsProperties.None) { this.wg = System.Windows.Forms.Internal.WindowsGraphics.FromGraphics(idc as Graphics, none); } } else { this.wg = idc as System.Windows.Forms.Internal.WindowsGraphics; if (this.wg != null) { this.idc = idc; } } if (this.wg == null) { this.idc = idc; this.wg = System.Windows.Forms.Internal.WindowsGraphics.FromHdc(idc.GetHdc()); } if ((flags & TextFormatFlags.LeftAndRightPadding) != TextFormatFlags.Default) { this.wg.TextPadding = TextPaddingOptions.LeftAndRightPadding; } else if ((flags & TextFormatFlags.NoPadding) != TextFormatFlags.Default) { this.wg.TextPadding = TextPaddingOptions.NoPadding; } }
// Helper method to overcome the poor GDI ellipse drawing routine // VSWhidbey #334097 private static void DrawAndFillEllipse(WindowsGraphics wg, WindowsPen borderPen, WindowsBrush fieldBrush, Rectangle bounds) { Debug.Assert(wg != null,"Calling DrawAndFillEllipse with null wg"); if (wg == null) { return; } wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 2, bounds.Y + 2, 8, 8)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 4, bounds.Y + 1, 4, 10)); wg.FillRectangle(fieldBrush, new Rectangle(bounds.X + 1, bounds.Y + 4, 10, 4)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 0), new Point(bounds.X + 8, bounds.Y + 0)); wg.DrawLine(borderPen, new Point(bounds.X + 4, bounds.Y + 11), new Point(bounds.X + 8, bounds.Y + 11)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 1), new Point(bounds.X + 4, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 1), new Point(bounds.X + 10, bounds.Y + 1)); wg.DrawLine(borderPen, new Point(bounds.X + 2, bounds.Y + 10), new Point(bounds.X + 4, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 8, bounds.Y + 10), new Point(bounds.X + 10, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 0, bounds.Y + 4), new Point(bounds.X + 0, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 11, bounds.Y + 4), new Point(bounds.X + 11, bounds.Y + 8)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 2), new Point(bounds.X + 1, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 1, bounds.Y + 8), new Point(bounds.X + 1, bounds.Y + 10)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 2), new Point(bounds.X + 10, bounds.Y + 4)); wg.DrawLine(borderPen, new Point(bounds.X + 10, bounds.Y + 8), new Point(bounds.X + 10, bounds.Y + 10)); }
protected override void WndProc(ref Message m) { switch (m.Msg) { // We don't want to fire the focus events twice - // once in the combobox and once in the ChildWndProc. case NativeMethods.WM_SETFOCUS: try { fireSetFocus = false; base.WndProc(ref m); } finally { fireSetFocus = true; } break; case NativeMethods.WM_KILLFOCUS: try { fireLostFocus = false; base.WndProc(ref m); // Nothing to see here... Just keep on walking... VSWhidbey 504477. // Turns out that with Theming off, we don't get quite the same messages as with theming on. // With theming on we get a WM_MOUSELEAVE after a WM_KILLFOCUS even if you use the Tab key // to move focus. Our response to WM_MOUSELEAVE causes us to repaint everything correctly. // With theming off, we do not get a WM_MOUSELEAVE after a WM_KILLFOCUS, and since we don't have a childwndproc // when we are a Flat DropDownList, we need to force a repaint. The easiest way to do this is to send a // WM_MOUSELEAVE to ourselves, since that also sets up the right state. Or... at least the state is the same // as with Theming on. // This is such a @#$(*&#@$ hack. if (!Application.RenderWithVisualStyles && GetStyle(ControlStyles.UserPaint) == false && this.DropDownStyle == ComboBoxStyle.DropDownList && (FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup)) { UnsafeNativeMethods.PostMessage(new HandleRef(this, Handle), NativeMethods.WM_MOUSELEAVE, 0, 0); } } finally { fireLostFocus = true; } break; case NativeMethods.WM_CTLCOLOREDIT: case NativeMethods.WM_CTLCOLORLISTBOX: m.Result = InitializeDCForWmCtlColor(m.WParam, m.Msg); break; case NativeMethods.WM_ERASEBKGND: WmEraseBkgnd(ref m); break; case NativeMethods.WM_PARENTNOTIFY: WmParentNotify(ref m); break; case NativeMethods.WM_REFLECT + NativeMethods.WM_COMMAND: WmReflectCommand(ref m); break; case NativeMethods.WM_REFLECT + NativeMethods.WM_DRAWITEM: WmReflectDrawItem(ref m); break; case NativeMethods.WM_REFLECT + NativeMethods.WM_MEASUREITEM: WmReflectMeasureItem(ref m); break; case NativeMethods.WM_LBUTTONDOWN: mouseEvents = true; base.WndProc(ref m); break; case NativeMethods.WM_LBUTTONUP: // Get the mouse location // NativeMethods.RECT r = new NativeMethods.RECT(); UnsafeNativeMethods.GetWindowRect(new HandleRef(this, Handle), ref r); Rectangle ClientRect = new Rectangle(r.left, r.top, r.right - r.left, r.bottom - r.top); int x = NativeMethods.Util.SignedLOWORD(m.LParam); int y = NativeMethods.Util.SignedHIWORD(m.LParam); Point pt = new Point(x, y); pt = PointToScreen(pt); //mouseEvents is used to keep the check that we get the WM_LBUTTONUP after //WM_LBUTTONDOWN or WM_LBUTTONDBLBCLK // combo box gets a WM_LBUTTONUP for focus change ... // if (mouseEvents && !ValidationCancelled) { mouseEvents = false; bool captured = Capture; if (captured && ClientRect.Contains(pt)) { OnClick(new MouseEventArgs(MouseButtons.Left, 1, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0)); OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, NativeMethods.Util.SignedLOWORD(m.LParam), NativeMethods.Util.SignedHIWORD(m.LParam), 0)); } base.WndProc(ref m); } else { CaptureInternal = false; DefWndProc(ref m); } break; case NativeMethods.WM_MOUSELEAVE: DefWndProc(ref m); OnMouseLeaveInternal(EventArgs.Empty); break; case NativeMethods.WM_PAINT: if (GetStyle(ControlStyles.UserPaint) == false && (FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup)) { using (WindowsRegion dr = new WindowsRegion(FlatComboBoxAdapter.dropDownRect)) { using (WindowsRegion wr = new WindowsRegion(this.Bounds)) { // Stash off the region we have to update (the base is going to clear this off in BeginPaint) NativeMethods.RegionFlags updateRegionFlags = (NativeMethods.RegionFlags)SafeNativeMethods.GetUpdateRgn(new HandleRef(this, this.Handle), new HandleRef(this, wr.HRegion), true); dr.CombineRegion(wr, dr, RegionCombineMode.DIFF); Rectangle updateRegionBoundingRect = wr.ToRectangle(); FlatComboBoxAdapter.ValidateOwnerDrawRegions(this, updateRegionBoundingRect); // Call the base class to do its painting (with a clipped DC). NativeMethods.PAINTSTRUCT ps = new NativeMethods.PAINTSTRUCT(); IntPtr dc; bool disposeDc = false; if (m.WParam == IntPtr.Zero) { dc = UnsafeNativeMethods.BeginPaint(new HandleRef(this, Handle), ref ps); disposeDc = true; } else { dc = m.WParam; } using (DeviceContext mDC = DeviceContext.FromHdc(dc)) { using (WindowsGraphics wg = new WindowsGraphics(mDC)) { if (updateRegionFlags != NativeMethods.RegionFlags.ERROR) { wg.DeviceContext.SetClip(dr); } m.WParam = dc; DefWndProc(ref m); if (updateRegionFlags != NativeMethods.RegionFlags.ERROR) { wg.DeviceContext.SetClip(wr); } using (Graphics g = Graphics.FromHdcInternal(dc)) { FlatComboBoxAdapter.DrawFlatCombo(this, g); } } } if (disposeDc) { UnsafeNativeMethods.EndPaint(new HandleRef(this, Handle), ref ps); } } return; } } base.WndProc(ref m); break; case NativeMethods.WM_PRINTCLIENT: // all the fancy stuff we do in OnPaint has to happen again in OnPrint. if (GetStyle(ControlStyles.UserPaint) == false && FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) { DefWndProc(ref m); if ((unchecked( (int) (long)m.LParam) & NativeMethods.PRF_CLIENT) == NativeMethods.PRF_CLIENT) { if (GetStyle(ControlStyles.UserPaint) == false && FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) { using (Graphics g = Graphics.FromHdcInternal(m.WParam)) { FlatComboBoxAdapter.DrawFlatCombo(this,g); } } return; } } base.WndProc(ref m); return; case NativeMethods.WM_SETCURSOR: base.WndProc(ref m); break; case NativeMethods.WM_SETFONT: //(bug 119265) if (Width == 0) { suppressNextWindosPos = true; } base.WndProc(ref m); break; case NativeMethods.WM_WINDOWPOSCHANGED: if (!suppressNextWindosPos) { base.WndProc(ref m); } suppressNextWindosPos = false; break; case NativeMethods.WM_NCDESTROY: base.WndProc(ref m); ReleaseChildWindow(); break; default: if (m.Msg == NativeMethods.WM_MOUSEENTER) { DefWndProc(ref m); OnMouseEnterInternal(EventArgs.Empty); break; } base.WndProc(ref m); break; } }
public void Dispose( bool disposing ) { Debug.Assert( disposing, "We should always dispose of this guy and not let GC do it for us!" ); if( this.wg != null ) { // We need to dispose of the WindowsGraphics if it is created by this class only, if the IDeviceContext is // a WindowsGraphics object we must not dispose of it since it is owned by the caller. if( this.wg != this.idc ) { // resets the hdc and disposes of the internal Graphics (if inititialized from one) which releases the hdc. this.wg.Dispose(); if( this.idc != null ) // not initialized from a Graphics idc. { this.idc.ReleaseHdc(); } } this.idc = null; this.wg = null; } }
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) { if (g.GetContextInfo() is object[] data && 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). // 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 = 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. 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); }
// the DataGridViewButtonCell uses this method internal static void PaintButtonBackground(WindowsGraphics wg, Rectangle bounds, WindowsBrush background) { wg.FillRectangle(background, bounds); }
internal static bool IsMeasurementDC(DeviceContext dc) { WindowsGraphics sharedGraphics = WindowsGraphicsCacheManager.GetCurrentMeasurementGraphics(); return(sharedGraphics != null && sharedGraphics.DeviceContext != null && sharedGraphics.DeviceContext.Hdc == dc.Hdc); }
protected override void WndProc(ref Message m) { switch (m.Msg) { case 7: try { this.fireSetFocus = false; base.WndProc(ref m); return; } finally { this.fireSetFocus = true; } break; case 8: break; case 15: if (!base.GetStyle(ControlStyles.UserPaint) && ((this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Popup))) { using (WindowsRegion region = new WindowsRegion(this.FlatComboBoxAdapter.dropDownRect)) { using (WindowsRegion region2 = new WindowsRegion(base.Bounds)) { IntPtr wParam; System.Windows.Forms.NativeMethods.RegionFlags flags = (System.Windows.Forms.NativeMethods.RegionFlags) System.Windows.Forms.SafeNativeMethods.GetUpdateRgn(new HandleRef(this, base.Handle), new HandleRef(this, region2.HRegion), true); region.CombineRegion(region2, region, RegionCombineMode.DIFF); Rectangle updateRegionBox = region2.ToRectangle(); this.FlatComboBoxAdapter.ValidateOwnerDrawRegions(this, updateRegionBox); System.Windows.Forms.NativeMethods.PAINTSTRUCT lpPaint = new System.Windows.Forms.NativeMethods.PAINTSTRUCT(); bool flag2 = false; if (m.WParam == IntPtr.Zero) { wParam = System.Windows.Forms.UnsafeNativeMethods.BeginPaint(new HandleRef(this, base.Handle), ref lpPaint); flag2 = true; } else { wParam = m.WParam; } using (DeviceContext context = DeviceContext.FromHdc(wParam)) { using (WindowsGraphics graphics = new WindowsGraphics(context)) { if (flags != System.Windows.Forms.NativeMethods.RegionFlags.ERROR) { graphics.DeviceContext.SetClip(region); } m.WParam = wParam; this.DefWndProc(ref m); if (flags != System.Windows.Forms.NativeMethods.RegionFlags.ERROR) { graphics.DeviceContext.SetClip(region2); } using (Graphics graphics2 = Graphics.FromHdcInternal(wParam)) { this.FlatComboBoxAdapter.DrawFlatCombo(this, graphics2); } } } if (flag2) { System.Windows.Forms.UnsafeNativeMethods.EndPaint(new HandleRef(this, base.Handle), ref lpPaint); } } return; } } base.WndProc(ref m); return; case 20: this.WmEraseBkgnd(ref m); return; case 0x47: if (!this.suppressNextWindosPos) { base.WndProc(ref m); } this.suppressNextWindosPos = false; return; case 130: base.WndProc(ref m); this.ReleaseChildWindow(); return; case 0x20: base.WndProc(ref m); return; case 0x30: if (base.Width == 0) { this.suppressNextWindosPos = true; } base.WndProc(ref m); return; case 0x133: case 0x134: goto Label_017F; case 0x201: this.mouseEvents = true; base.WndProc(ref m); return; case 0x202: { System.Windows.Forms.NativeMethods.RECT rect = new System.Windows.Forms.NativeMethods.RECT(); System.Windows.Forms.UnsafeNativeMethods.GetWindowRect(new HandleRef(this, base.Handle), ref rect); Rectangle rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); int x = System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam); int y = System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam); Point p = new Point(x, y); p = base.PointToScreen(p); if (this.mouseEvents && !base.ValidationCancelled) { this.mouseEvents = false; if (base.Capture && rectangle.Contains(p)) { this.OnClick(new MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); this.OnMouseClick(new MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.NativeMethods.Util.SignedLOWORD(m.LParam), System.Windows.Forms.NativeMethods.Util.SignedHIWORD(m.LParam), 0)); } base.WndProc(ref m); return; } base.CaptureInternal = false; this.DefWndProc(ref m); return; } case 0x210: this.WmParentNotify(ref m); return; case 0x202b: this.WmReflectDrawItem(ref m); return; case 0x202c: this.WmReflectMeasureItem(ref m); return; case 0x2111: this.WmReflectCommand(ref m); return; case 0x2a3: this.DefWndProc(ref m); this.OnMouseLeaveInternal(EventArgs.Empty); return; case 0x318: if ((base.GetStyle(ControlStyles.UserPaint) || (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Popup)) { goto Label_04EF; } this.DefWndProc(ref m); if ((((int) ((long) m.LParam)) & 4) != 4) { goto Label_04EF; } if ((!base.GetStyle(ControlStyles.UserPaint) && (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat)) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Popup)) { using (Graphics graphics3 = Graphics.FromHdcInternal(m.WParam)) { this.FlatComboBoxAdapter.DrawFlatCombo(this, graphics3); } } return; default: if (m.Msg == System.Windows.Forms.NativeMethods.WM_MOUSEENTER) { this.DefWndProc(ref m); this.OnMouseEnterInternal(EventArgs.Empty); return; } base.WndProc(ref m); return; } try { this.fireLostFocus = false; base.WndProc(ref m); if (((!Application.RenderWithVisualStyles && !base.GetStyle(ControlStyles.UserPaint)) && (this.DropDownStyle == ComboBoxStyle.DropDownList)) && ((this.FlatStyle == System.Windows.Forms.FlatStyle.Flat) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Popup))) { System.Windows.Forms.UnsafeNativeMethods.PostMessage(new HandleRef(this, base.Handle), 0x2a3, 0, 0); } return; } finally { this.fireLostFocus = true; } Label_017F: m.Result = this.InitializeDCForWmCtlColor(m.WParam, m.Msg); return; Label_04EF: base.WndProc(ref m); }
/// <summary> /// 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. /// </summary> public static WindowsGraphics FromGraphics(Graphics g) { ApplyGraphicsProperties properties = ApplyGraphicsProperties.All; return(WindowsGraphics.FromGraphics(g, properties)); }