123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SmartCoalApplication.SystemLayer
- {
- public sealed class NullGraphics
- : IDisposable
- {
- private IntPtr hdc = IntPtr.Zero;
- private Graphics graphics = null;
- private bool disposed = false;
- public Graphics Graphics
- {
- get
- {
- return graphics;
- }
- }
- public NullGraphics()
- {
- this.hdc = SafeNativeMethods.CreateCompatibleDC(IntPtr.Zero);
- if (this.hdc == IntPtr.Zero)
- {
- NativeMethods.ThrowOnWin32Error("CreateCompatibleDC returned NULL");
- }
- this.graphics = Graphics.FromHdc(this.hdc);
- }
- ~NullGraphics()
- {
- Dispose(false);
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- private void Dispose(bool disposing)
- {
- if (!disposed)
- {
- if (disposing)
- {
- this.graphics.Dispose();
- this.graphics = null;
- }
- SafeNativeMethods.DeleteDC(this.hdc);
- disposed = true;
- }
- }
- }
- }
|