title: How do I set the background image to None, or some other default value, in an image button?
body: <p>I'm building off <a href="https://stackoverflow.com/q/4796021/869912">this question</a> and creating a simple ImageButton class that represents a button containing only an image. I implemented (at least I believe I did) the suggestions in <a href="https://stackoverflow.com/a/4796070/869912">this answer</a>, but I'm still getting an exception with this code:</p>
  
  <pre><code>public class ImageButton : Button
  {
      // Overrides the property
      public override Image BackgroundImage
      {
          get { return base.BackgroundImage; }
          set
          {
              base.BackgroundImage = value;
              if (value != null) this.Size = value.Size;
          }
      }
  
      // Shadows the property (note the -new- keyword)
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
      public new Size Size
      {
          get
          {
              return base.Size;
          }
          set
          {
              base.Size = value;
          }
      }
  
      public ImageButton()
      {
          this.BackgroundImage = base.BackgroundImage;
          this.BackgroundImageChanged += new EventHandler(ImageButton_BackgroundImageChanged);
      }
  
      void ImageButton_BackgroundImageChanged(object sender, EventArgs e)
      {
          this.Size = this.BackgroundImage.Size;
      }
  
      protected override void OnPaint(PaintEventArgs e)
      {
          e.Graphics.DrawImage(BackgroundImage, 0, 0); // &lt;-- Error occurs here
      }
  
      protected override void OnPaintBackground(PaintEventArgs e)
      {
          // Do nothing
      }
  }
  </code></pre>
  
  <p>When I try to add this control to the designer, I get </p>
  
  <blockquote>
    <p>The control ImageButton has thrown an unhandled exception in the
    designer and has been disabled. </p>
    
    <p>Exception: Value cannot be null. Parameter name: image</p>
    
    <p>Stack trace: ImageButton.OnPaint(PaintEventArgs e) in
    ImageButton.cs:line48</p>
  </blockquote>
  
  <p>Line 48 is this line:</p>
  
  <pre><code>e.Graphics.DrawImage(BackgroundImage, 0, 0);
  </code></pre>
  
  <p>I realise that this error is thrown because <code>BackgroundImage</code> is not set to a value, but I'm unsure how to do so in the code. In the actual application, this class will never be added to the designer, but rather added programmatically. How can I fix this exception?</p>