title: Cannot access a non-static member of outer type X via nested type Y
body: <p>The error was too long to type in the title. So this is what it says:</p>
  
  <blockquote>
    <p>Error 1   Cannot access a non-static member of outer type
    'WindowsFormsApplication3.Form1' via nested type
    'WindowsFormsApplication3.Form1.PCPrint'  C:\Users\Andrew\documents\visual
    studio
    2010\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs  407 39  WindowsFormsApplication3</p>
  </blockquote>
  
  <p>I am trying to print my form however, it is not recognising the text box, txtName.Text. Why?
  Here is the code:</p>
  
  <pre><code>        public class PCPrint : System.Drawing.Printing.PrintDocument
          {
              private Font _font;
  
              private string _text;
  
              private string TextToPrint
              {
                  get { return _text; }
                  set { _text = value; }
              }
              public Font PrinterFont
              {
                  get { return _font; }
                  set { _font = value; }
              }
              public PCPrint()
                  : base()
              {
                  _text = string.Empty;
              }
              public PCPrint(string str)
                  : base()
              {
                  _text = str;
              }
              protected override void OnBeginPrint(PrintEventArgs e)
              {
                  base.OnBeginPrint(e);
                  if (_font == null)
                  {
                      _font = new Font("Times New Roman", 10);
                  }
              }
              protected override void OnPrintPage(PrintPageEventArgs e)
              {
                  base.OnPrintPage(e);
  
                  int printHeight;
                  int printWidth;
                  int leftMargin;
                  int rightMargin;
                  Int32 lines;
                  Int32 chars;
                  {
                      printHeight = base.DefaultPageSettings.PaperSize.Height -
                          base.DefaultPageSettings.Margins.Top - base.DefaultPageSettings.Margins.Bottom;
                      printWidth = base.DefaultPageSettings.PaperSize.Width -
                          base.DefaultPageSettings.Margins.Left - base.DefaultPageSettings.Margins.Right;
                      leftMargin = base.DefaultPageSettings.Margins.Left;
                      rightMargin = base.DefaultPageSettings.Margins.Right;
                  }
                  if (base.DefaultPageSettings.Landscape)
                  {
                      int tmp;
                      tmp = printHeight;
                      printHeight = printWidth;
                      printWidth = tmp;
                  }
                  Int32 numLines = (int)printHeight / PrinterFont.Height;
  
                  RectangleF printArea = new RectangleF(leftMargin, rightMargin, printWidth, printHeight);
  
                  StringFormat format = new StringFormat(StringFormatFlags.LineLimit);
  
                  e.Graphics.MeasureString(_text.Substring(RemoveZeros(curChar)), PrinterFont, new SizeF(printWidth, printHeight), format, out chars, out lines);
  
                  e.Graphics.DrawString(_text.Substring(RemoveZeros(curChar)), PrinterFont, Brushes.Black, printArea, format);
  
                  curChar += chars;
  
                  if (curChar &lt; _text.Length)
                  {
                      e.HasMorePages = true;
                  }
                  else
                  {
                      e.HasMorePages = false;
                      curChar = 0;
                  }
              }
              public int RemoveZeros(int value)
              {
                  switch (value)
                  {
                      case 0:
                          return 1;
                      default:
                          return value;
                  }
  
              }
              public void PrintDocument()
              {
                  PCPrint printer = new PCPrint();
                  printer.PrinterFont = new Font("Verdana", 10);
                  printer.TextToPrint = txtName.Text; //ERROR IS HERE
                  printer.Print();
              }
  
              private void btnCreate_Click(object sender, EventArgs e)
              {
                PrintDocument();
              }
          }
      }
  }
  </code></pre>