H
H
humminbird2015-02-08 18:28:13
Visual Basic
humminbird, 2015-02-08 18:28:13

Is it possible to update the form after changing the data?

Hello !
I have a working code

Imports NAudio.Wave
Public Class MainForm
Dim Str As String
Public Sub New()
InitializeComponent()
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Str = TextBox1.Text
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim waveOut = New WaveOut()
Dim osc = New SineWaveOscillator(44100)
osc.Frequency = Str
osc.Amplitude = 8192
waveOut.Init(osc)
waveOut.Play()
End Sub
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
Public Class SineWaveOscillator
Inherits WaveProvider16
Dim phaseAngle As Double
Public Sub New(sampleRate As Int32)
MyBase.New(sampleRate, 1)
End Sub
Public Property Frequency As Double
Public Property Amplitude As Short
Public Overrides Function Read(buffer() As Short, _
offset As Integer, sampleCount As Integer) As Integer
For index = 0 To sampleCount
buffer(offset + index) = Amplitude * Math.Sin(phaseAngle)
phaseAngle += 2 * Math.PI * Frequency / WaveFormat.SampleRate
If phaseAngle > 2 * Math.PI Then
phaseAngle -= 2 * Math.PI
End If
Next
Return sampleCount
End Function
End Class

I start the assembly => going to => starts
everything is ok ... but when you enter the frequency a second time and press the play button, it does not update the form, but superimposes a new one on the old
one, is it possible to somehow update the form by button or automatically?
Or is it due to the fact that I did not collect completely?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question