ShowWaveForm'�A C# Implementation of CWaveForm

Environment: VS.NET


ShowWaveForm is based from a C++ class, called CWaveFile, written by Alexander Beletsky. This is a port to C#, with some added features. A small .wav file is included in the demo project .zip file for testing.


WaveFile.cs is the main class. It reads and parses the WAV file headers. When passed a PaintEventArgs (typically from an OnPaint() event), it will draw the waveform. The class also allows for zooming in/out on the waveform.


Using the class is very simple. Here is the sample project file open menu handler:

private void fileOpen_Click(object sender, System.EventArgs e)
  OpenFileDialog fileDlg = new OpenFileDialog();

  if ( fileDlg.ShowDialog() == DialogResult.OK )
    wave = new WaveFile( fileDlg.FileName );

    sbpMainPanel.Text = "Reading .WAV file...";

    wave.Read( );

    sbpMainPanel.Text = "Finished Reading .WAV file...";

    m_DrawWave = true;

    Refresh( );


And here is the Paint handler of the demo project:

private void Form1_Paint( object sender,
                          System.Windows.Forms.PaintEventArgs e)
  Pen pen = new Pen( ForeColor );

  if ( m_DrawWave )
    sbpMainPanel.Text = "Drawing .WAV file...";

    wave.Draw( e, pen );

    sbpMainPanel.Text = "Finished drawing .WAV file...";

The last interesting thing in the demo project is the MouseWheel handler, which controls zooming of the waveform:

protected override void OnMouseWheel( MouseEventArgs mea )
  if ( mea.Delta * SystemInformation.MouseWheelScrollLines /
                   120 > 0 )
    wave.ZoomIn( );
    wave.ZoomOut( );

  Refresh( );



This is my first attempt at programming in C#/.NET. So, please comment on everything in this code! Specifically, I have questions about the following:

  • Drawing the waveform is very slow for large files, perhaps because of using PageScale?
  • How to catch some of the errors that can occur in zooming in/out too far
  • Drawing of stereo waveforms


Download demo project - 11 Kb
Download source - 2 Kb


  • Works on Linux too :)

    Posted by t3rmin4t0r on 06/09/2004 08:52am

    It works - though I think the color handling was ugly (read that as I hate white bgs :) No changes except color .. if you look at the terminal , you'll see the compile command too. Anyway nice portable code :)

  • Because it's your first attempt, it's very good.

    Posted by Wosiu on 04/13/2004 01:26pm

    Otherwise it would be Average. Thank you very much this is exactly what I was looking for. I'm currently analyzing your code to write something more advanced as my university project ;) thx

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date