1

我试图理解为什么下面的代码(waveInStream.DataAvailable):

Private Sub cmbRecord_Click(sender As Object, e As EventArgs)
    Dim saveFileDialog As New SaveFileDialog()
    saveFileDialog.Title = "Select output file:"
    saveFileDialog.Filter = "WAV Files (*.wav)|*.wav"
    saveFileDialog.FileName = outputFilename

    If saveFileDialog.ShowDialog() = DialogResult.OK Then
        outputFilename = saveFileDialog.FileName

        waveInStream = New WaveIn(44100, 2)
        writer = New WaveFileWriter(outputFilename, waveInStream.WaveFormat)
        waveInStream.DataAvailable += New EventHandler(Of WaveInEventArgs)(AddressOf waveInStream_DataAvailable)
        waveInStream.StartRecording()


        ' Just controling the objects on the screen.
        cmbRecord.Enabled = False
        cmbStop.Enabled = True
    End If
End Sub

给我错误:

Error 1 'Public Event DataAvailable(sender As Object, e As NAudio.Wave.WaveInEventArgs)'
is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

我正在使用此处的示例将上面的代码从 c# 转换为 VB.net

转换为VB的c#是这样的:

private void cmbRecord_Click(object sender, EventArgs e)
    {
        SaveFileDialog saveFileDialog = new SaveFileDialog();
        saveFileDialog.Title = "Select output file:";
        saveFileDialog.Filter = "WAV Files (*.wav)|*.wav";
        saveFileDialog.FileName = outputFilename;
        if (saveFileDialog.ShowDialog() == DialogResult.OK)
        {
            outputFilename = saveFileDialog.FileName;

            waveInStream = new WaveIn(44100,2);
            writer = new WaveFileWriter(outputFilename, waveInStream.WaveFormat);

            waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
            waveInStream.StartRecording();


            // Just controling the objects on the screen.
            cmbRecord.Enabled = false;
            cmbStop.Enabled = true;
        }
    }

任何帮助都会很棒!

谢谢!

4

1 回答 1

2

尝试更换

waveInStream.DataAvailable += New EventHandler(Of WaveInEventArgs)(AddressOf waveInStream_DataAvailable)

AddHandler waveInStream.DataAvailable, AddressOf waveInStream_DataAvailable
于 2013-04-03T17:58:53.080 回答