using System; using System.Drawing; using System.Windows.Forms; using Assembly = System.Reflection.Assembly; using Path = System.IO.Path; using ResourceManager = System.Resources.ResourceManager; namespace ProcessInfo { public class Throbber : UserControl { private Image stoppedImage; private Image throbImage; private PictureBox pictureBox; private bool throbbing = false; public Throbber() : base() { this.Name = "Throbber"; this.Size = new Size( 16, 16 ); ResourceManager resources = new ResourceManager( "ProcessInfo.Throbber", this.GetType().Assembly ); throbImage = (Bitmap)resources.GetObject( "ThrobberOn" ); stoppedImage = (Bitmap)resources.GetObject( "ThrobberOff" ); pictureBox = new PictureBox(); this.Controls.Add( pictureBox ); SetImage(); } protected override void Dispose( bool disposing ) { if ( disposing ) { pictureBox.Dispose(); stoppedImage.Dispose(); throbImage.Dispose(); } base.Dispose( disposing ); } public bool Throbbing { get { return throbbing; } set { throbbing = value; SetImage(); } } public Image StoppedImage { get { return stoppedImage; } set { if ( value == null ) { throw new ArgumentNullException( "value" ); } stoppedImage.Dispose(); stoppedImage = value; SetImage(); } } public Image ThrobImage { get { return throbImage; } set { if ( value == null ) { throw new ArgumentNullException( "value" ); } throbImage.Dispose(); throbImage = value; SetImage(); } } private void SetImage() { Image image = ( throbbing ) ? this.throbImage : this.stoppedImage; // so that the throbber doesn't reset unless its state has changed if ( pictureBox.Image != image ) { pictureBox.Image = image; } } } }