title: Cannot access a non-static member of outer type 'FormMain' via nested type 'FormMain.ImageDelegateClass'
body: <p>I need to update a C# WinForms PictureBox from a MemoryStream input.
  I was able to accomplish this using </p>
  
  <pre><code>pictureBox.Image = new Bitmap(new MemoryStream(payload));
  </code></pre>
  
  <p>in the thread that parses the stream [<code>RxThread()</code>] but was <a href="https://stackoverflow.com/questions/6527825/is-it-evil-to-update-a-picturebox-from-a-background-c-thread">advised to use a delegate</a> to avoid undesirable effects.
  So I've implemented this:</p>
  
  <pre><code>private void RxThread()
  {
      ...
      var imageDelegateClass = new ImageDelegateClass();
      var imageDelegate = new ImageDelegate(imageDelegateClass.SetImage);
      imageDelegate(payload);
      ...
  }
  
  delegate void ImageDelegate(byte[] payload);
  class ImageDelegateClass
  {
      public void SetImage(byte[] payload)
      {
          pictureBox.Image = new Bitmap(new MemoryStream(payload));
      }
  }
  </code></pre>
  
  <p>but get the following error code when I try to compile:</p>
  
  <blockquote>
    <p>Cannot access a non-static member of
    outer type 'FormMain' via nested type
    'FormMain.ImageDelegateClass'</p>
  </blockquote>
  
  <p>I am sure its a bad idea to make pictureBox static since it is WinForms generated.
  I know the repair is probably simple but I am a bit new to C#.
  I have read the chapter on Delegates in Jon Skeets C# In Depth 2nd Edition multiple times but this is the first time I've actually tried to use one.
  How can I change <code>SetImage()</code> so it can access pictureBox?</p>