title: passing PaintEventArgs to my function causes an error
body: <p>I have tried to create a function that draws my map. My function is like this :</p>
  
  <pre><code>public void DrawMap(PaintEventArgs e)
  {
      List&lt;Point&gt; lstPointLeft = new List&lt;Point&gt;();
  
      foreach (var t in lstSensorLeft)
      {
          Point objPoint = new Point(t.XLocation, t.YLocation);
          lstPointLeft.Add(objPoint);
          Rectangle rectSens = new Rectangle(t.XLocation, t.YLocation, 3, 3);
          e.Graphics.FillRectangle(whiteBrush, rectSens);
          if (t.StationId != null)
          {
              Rectangle rectEhsansq = new Rectangle(t.XLocation - 6, t.YLocation - 6, 12, 12);
              e.Graphics.FillRectangle(blueBrush, rectEhsansq);
  
          }
      }
  
      List&lt;Point&gt; lstPointRight = new List&lt;Point&gt;();
  
      foreach (var t in lstSensorRight)
      {
          Point objPoint = new Point(t.XLocation + 30, t.YLocation + 30);
          lstPointRight.Add(objPoint);
          Rectangle rectSens = new Rectangle(t.XLocation + 30, t.YLocation + 30, 3, 3);
          e.Graphics.FillRectangle(whiteBrush, rectSens);
          if (t.StationId != null)
          {
              Rectangle rectPosition = new Rectangle(t.XLocation + 24, t.YLocation + 24, 12, 12);
              e.Graphics.FillRectangle(blueBrush, rectPosition);
  
              Rectangle rectTrainState = new Rectangle(t.XLocation + 27, t.YLocation + 27, 7, 7);
              e.Graphics.FillRectangle(RedBrush, rectTrainState);
  
          }
      }
  
  
      e.Graphics.DrawLines(pLine, lstPointLeft.ToArray());
      e.Graphics.DrawLines(pLine, lstPointRight.ToArray());
      //ShowOnlineTrain(e);
      //Thread newThread = new Thread(() =&gt; ShowOnlineTrain(e));
      //newThread.Start();
  }
  </code></pre>
  
  <p>This function draws my map, I have a <code>PictureBox</code> in my form that shows my map. This function <code>DrawMap</code> draws a railway map without anything. My problem is how do I call this function in <code>page_Load</code>? I have tried something like this :</p>
  
  <p>I have created a global painteventarg:</p>
  
  <pre><code>private PaintEventArgs a;
  </code></pre>
  
  <p>And in <code>form_load</code> I am doing this :</p>
  
  <pre><code>private void frmMain_Load(object sender, EventArgs e)
  {
  
      DrawMap(a);
  
  }
  </code></pre>
  
  <p>In this line :</p>
  
  <pre><code>e.Graphics.FillRectangle(whiteBrush, rectSens);
  </code></pre>
  
  <p>I am getting below error :</p>
  
  <pre><code>{System.NullReferenceException: Object reference not set to an instance of an object.
     at PresentationLayer.PreLayer.frmMain.DrawMap(PaintEventArgs e) 
  </code></pre>