using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; namespace BSE.Windows.Forms { /// /// Set the SmoothingMode=AntiAlias until instance disposed. /// public class UseAntiAlias : IDisposable { #region FieldsPrivate private Graphics m_graphics; private SmoothingMode m_smoothingMode; #endregion #region MethodsPublic /// /// Initialize a new instance of the UseAntiAlias class. /// /// Graphics instance. public UseAntiAlias(Graphics graphics) { if(graphics == null) { throw new ArgumentNullException("graphics", string.Format(System.Globalization.CultureInfo.InvariantCulture, Demo.WindowsForms.Properties.Resources.IDS_ArgumentException, "graphics")); } this.m_graphics = graphics; this.m_smoothingMode = m_graphics.SmoothingMode; this.m_graphics.SmoothingMode = SmoothingMode.AntiAlias; } /// /// destructor of the UseAntiAlias class. /// ~UseAntiAlias() { Dispose(false); } /// /// Releases all resources used by the class. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion #region MethodsProtected /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected virtual void Dispose(bool disposing) { if(disposing == true) { //Revert the SmoothingMode back to original setting. this.m_graphics.SmoothingMode = this.m_smoothingMode; } } #endregion } }