title: NAudio and ZedGraph Waveform Plotting
body: <pre><code>    int window;
      LineItem myCurve1;
      LineItem myCurve2;
      public void DrawWave(ZedGraphControl zgc)
      {
  
          NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName));
          WaveFileReader wavFile = new WaveFileReader(open.FileName);
          byte[] mainBuffer = new byte[wave.Length];
  
          float fileSize = (float)wavFile.Length / 1048576;
          if (fileSize &lt; 2)
              window = 8;
          else if (fileSize &gt; 2 &amp;&amp; fileSize &lt; 4)
              window = 16;
          else if (fileSize &gt; 4 &amp;&amp; fileSize &lt; 8)
              window = 32;
          else if (fileSize &gt; 8 &amp;&amp; fileSize &lt; 12)
              window = 128;
          else if (fileSize &gt; 12 &amp;&amp; fileSize &lt; 20)
              window = 256;
          else if (fileSize &gt; 20 &amp;&amp; fileSize &lt; 30)
              window = 512;
          else
              window = 2048;
  
          float[] fbuffer = new float[mainBuffer.Length / window];
          wave.Read(mainBuffer, 0, mainBuffer.Length);
  
          for (int i = 0; i &lt; fbuffer.Length; i++)
          {
              fbuffer[i] = (BitConverter.ToSingle(mainBuffer, i * window));
          }
  
          double time = wave.TotalTime.TotalSeconds;
          GraphPane myPane = zgc.GraphPane;
          PointPairList list1 = new PointPairList();
          PointPairList list2 = new PointPairList();
          for (int i = 0; i &lt; fbuffer.Length; i++)
          {
              list1.Add(i, fbuffer[i]);
          }
          list2.Add(0, 0);
          list2.Add(time, 0);
          if (myCurve1 != null &amp;&amp; myCurve2 != null)
          {
              myCurve1.Clear();
              myCurve2.Clear();
          }
  
          myCurve1 = myPane.AddCurve(null, list1, Color.Red, SymbolType.None);
          myCurve1.IsX2Axis = true;
          myCurve2 = myPane.AddCurve(null, list2, Color.Black, SymbolType.None);
          myPane.XAxis.Scale.MaxAuto = true;
          myPane.XAxis.Scale.MinAuto = true;
          zgc.AxisChange();
          zgc.Invalidate();
      }
  </code></pre>
  
  <p>I have this code to plot waveform in ZedGraph. It works fine except one thing.After drawing a waveform, i choose a new file to draw but i must clear the old one. I tried to define <code>LineItem</code> in global so i can write <code>if(myCruver != null) myCurve.Clear();</code> this condition.However it does not clear the old drawing. What am i suppose to do to solve this problem? </p>