Hello, I'm currently trying to make a beat generator, which allows you to add several labels (boxes) onto a panel, and then sound will be played when the "play slider" reaches the same x-value. However, i can't make the slider find the boxes.
OK, so this is what I've got so far! Clicking my button, a label named sound0, sound1, sound2 is added to my panel_back (which is the background of the player)
This works, and i see my labels being named sound0, sound1, sound3 in the form. Now, I've added different handlers to make them moveable around the form. This works aswell, and this is my code.
However, i cannot figure out how to make my labels being played, when i have a panel named panel_play to go across the form (with a timer). I've tried something like this, but it doesn't work.
It gives an error at the If-statement. Am i doing something wrong with just this if-statement, or should do something different when adding labels to the panel?
OK, so this is what I've got so far! Clicking my button, a label named sound0, sound1, sound2 is added to my panel_back (which is the background of the player)
VB.NET:
Private Sub btn_addkick_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addkick.Click
Dim tempsound As New Label
Me.panel_back.Controls.Add(tempsound)
tempsound.Size = New Size(50, 25)
tempsound.Location = New Point(100, 100)
tempsound.BackColor = Color.Aqua
tempsound.Text = "sound" & number_sound.ToString
AddHandler tempsound.MouseDown, AddressOf sound_MouseDown
AddHandler tempsound.MouseMove, AddressOf sound_MouseMove
AddHandler tempsound.MouseUp, AddressOf sound_MouseUp
tempsound.Name = "sound" & number_sound.ToString
number_sound += 1
End Sub
This works, and i see my labels being named sound0, sound1, sound3 in the form. Now, I've added different handlers to make them moveable around the form. This works aswell, and this is my code.
VB.NET:
Private Sub sound_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dragging = True
StartX = e.X
StartY = e.Y
End Sub
Private Sub sound_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If Dragging = True Then
sender.Left = (sender.Left + e.X) - StartX
sender.Top = (sender.Top + e.Y) - StartY
End If
End Sub
Private Sub sound_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dragging = False
End Sub
However, i cannot figure out how to make my labels being played, when i have a panel named panel_play to go across the form (with a timer). I've tried something like this, but it doesn't work.
VB.NET:
Private Sub timer_play_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer_play.Tick
panel_play.Location = New Point(panel_play.Location.X + 1, panel_play.Location.Y)
Do Until check_sound >= number_sound
If panel_play.Location.X = sound(check_sound).Location.X Then
My.Computer.Audio.Play(My.Resources.kick, AudioPlayMode.Background)
End If
check_sound += 1
Loop
If panel_play.Location.X = 400 Then
panel_play.Location = New Point(0, panel_play.Location.Y)
End If
End Sub
It gives an error at the If-statement. Am i doing something wrong with just this if-statement, or should do something different when adding labels to the panel?