public void DeleteObject(IntPtr handle, GdiObjectType type) { IntPtr zero = IntPtr.Zero; switch (type) { case GdiObjectType.Pen: if (handle == this.hCurrentPen) { IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(this, this.hInitialPen)); this.hCurrentPen = IntPtr.Zero; } zero = handle; break; case GdiObjectType.Brush: if (handle == this.hCurrentBrush) { IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(this, this.hInitialBrush)); this.hCurrentBrush = IntPtr.Zero; } zero = handle; break; case GdiObjectType.Bitmap: if (handle == this.hCurrentBmp) { IntUnsafeNativeMethods.SelectObject(new HandleRef(this, this.Hdc), new HandleRef(this, this.hInitialBmp)); this.hCurrentBmp = IntPtr.Zero; } zero = handle; break; } IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, zero)); }
public void Dispose(bool disposing) { if (this.nativeHandle != IntPtr.Zero) { if (this.ownHandle) { IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, this.nativeHandle)); } this.nativeHandle = IntPtr.Zero; if (disposing) { GC.SuppressFinalize(this); } } }
internal void Dispose(bool disposing) { bool flag = false; if ((this.ownHandle && (!this.ownedByCacheManager || !disposing)) && ((this.everOwnedByCacheManager || !disposing) || !DeviceContexts.IsFontInUse(this))) { IntUnsafeNativeMethods.DeleteObject(new HandleRef(this, this.hFont)); this.hFont = IntPtr.Zero; this.ownHandle = false; flag = true; } if (disposing && (flag || !this.ownHandle)) { GC.SuppressFinalize(this); } }