www.pudn.com > waveindemo.rar > Form1.cs
using System;
using System.IO;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
///
/// Summary description for Form1.
///
public class MainForm : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button StopButton;
private System.Windows.Forms.Button StartButton;
private System.Windows.Forms.OpenFileDialog OpenDlg;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button Suspend;
private System.Windows.Forms.Button Continue;
private System.Windows.Forms.SaveFileDialog SaveDig;
private System.Windows.Forms.Button File;
WaveLib.IWaveControl wave ;
public MainForm()
{
InitializeComponent();
wave = new WaveLib.Wave();
wave.ErrorEvent+=new WaveLib.ErrorEventHandle(wave_ErrorEvent);
wave.RecordQuality = WaveLib.Quality.Height;
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.StartButton = new System.Windows.Forms.Button();
this.StopButton = new System.Windows.Forms.Button();
this.OpenDlg = new System.Windows.Forms.OpenFileDialog();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.Suspend = new System.Windows.Forms.Button();
this.Continue = new System.Windows.Forms.Button();
this.SaveDig = new System.Windows.Forms.SaveFileDialog();
this.File = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// StartButton
//
this.StartButton.Location = new System.Drawing.Point(104, 8);
this.StartButton.Name = "StartButton";
this.StartButton.Size = new System.Drawing.Size(86, 26);
this.StartButton.TabIndex = 0;
this.StartButton.Text = "Start";
this.StartButton.Click += new System.EventHandler(this.StartButton_Click);
//
// StopButton
//
this.StopButton.Location = new System.Drawing.Point(200, 8);
this.StopButton.Name = "StopButton";
this.StopButton.Size = new System.Drawing.Size(86, 26);
this.StopButton.TabIndex = 1;
this.StopButton.Text = "Stop";
this.StopButton.Click += new System.EventHandler(this.StopButton_Click);
//
// OpenDlg
//
this.OpenDlg.DefaultExt = "wav";
this.OpenDlg.Filter = "WAV files|*.wav";
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.Location = new System.Drawing.Point(304, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(240, 23);
this.label1.TabIndex = 2;
this.label1.Text = "label1";
//
// Suspend
//
this.Suspend.Location = new System.Drawing.Point(8, 48);
this.Suspend.Name = "Suspend";
this.Suspend.Size = new System.Drawing.Size(88, 23);
this.Suspend.TabIndex = 3;
this.Suspend.Text = "Suspend";
this.Suspend.Click += new System.EventHandler(this.Suspend_Click);
//
// Continue
//
this.Continue.Location = new System.Drawing.Point(104, 48);
this.Continue.Name = "Continue";
this.Continue.Size = new System.Drawing.Size(88, 23);
this.Continue.TabIndex = 4;
this.Continue.Text = "Continue";
this.Continue.Click += new System.EventHandler(this.Resume_Click);
//
// SaveDig
//
this.SaveDig.Filter = "WAV files|*.wav";
//
// File
//
this.File.Location = new System.Drawing.Point(8, 8);
this.File.Name = "File";
this.File.Size = new System.Drawing.Size(86, 26);
this.File.TabIndex = 5;
this.File.Text = "File";
this.File.Click += new System.EventHandler(this.File_Click);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(554, 79);
this.Controls.Add(this.File);
this.Controls.Add(this.Continue);
this.Controls.Add(this.Suspend);
this.Controls.Add(this.label1);
this.Controls.Add(this.StopButton);
this.Controls.Add(this.StartButton);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MainForm";
this.Text = "Full-duplex audio sample";
this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
wave.Stop();
}
private void StartButton_Click(object sender, System.EventArgs e)
{
wave.Start();
timer1.Start();
}
private void StopButton_Click(object sender, System.EventArgs e)
{
wave.Stop();
timer1.Stop();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if(wave == null ) return;
label1.Text = Path.GetFileName(wave.SavedFile) + " = " + (wave.RecordSize/1024).ToString() + "|";
label1.Text += wave.RecordTimeSpan.Hours.ToString()
+ ":" + wave.RecordTimeSpan.Minutes.ToString()
+ ":" + wave.RecordTimeSpan.Seconds.ToString() ;
}
private void Suspend_Click(object sender, System.EventArgs e)
{
wave.Suspend();
}
private void Resume_Click(object sender, System.EventArgs e)
{
wave.Continue();
}
private void wave_ErrorEvent(Exception e, string error)
{
MessageBox.Show(e.Message);
}
private void File_Click(object sender, System.EventArgs e)
{
DialogResult dr = SaveDig.ShowDialog();
if(dr==DialogResult.OK)
{
wave.SavedFile = SaveDig.FileName;;
}
}
}
}