Help with PictureBoxes

mayjay

New member
Joined
Nov 5, 2011
Messages
2
Programming Experience
Beginner
Hi I'm pretty new to using VB and needed some help with a project I'm working on. I'm trying to create a virtual piano using pictureboxes to represent keys that play .wav file versions of notes. I've gotten this to work fine; however, I'm having trouble with two features I want to implement.

The first feature is to be able to save what I play in a text file. I thought I could use this code but I'm getting an error.

Dim swSong As IO.StreamWriter = IO.File.CreateText("song.txt")
If PictureBox1_click Then
swSong.WriteLine("C") 'The note represented by PictureBox1
End If
swSong.Close()

The second feature is to play random keys using the random class. Is there any way I could store the pictureboxes in an array and then use the random class?

Thanks!
 
Reading first paragraph I could have sworn you were going to ask how to connect ten fingers and two feet to the... well nevermind. Doubleclick the control in designer and you will get an event handler for the default event, which for PictureBox class is the Click event, which is what it seems you want to detect.
 
Thanks for the response. I've already done that for the sub to play the note. Here's an example:

Private Sub PictureBox1_Click(ByVal...) Handles PictureBox1.Click
playC() 'Where playC() is already defined as Private Sub playC()
My.Computer.Audio.Play(My.Resources.c, AudioPlayMode.Background)
End Sub
End Sub


I have this code in my Menu Control to save the played notes in a text file. Ex:

Private Sub SaveToolStripMenuItem_Click(ByVal...) Handles SaveToolStripMenuItem.Click
Dim swSong As IO.StreamWriter = IO.File.CreateText("song.txt")
If PictureBox1_click Then
swSong.WriteLine("C") 'The note represented by PictureBox1
End If

So I guess my question is what do I put in the If statement to recognize the PictureBox click event?

PS: sorry if I'm explaining this terribly. I'm just frustrated trying to get this to work.
 
You would have to store that information when picturebox was clicked, for example using a variable, and use it later when you was writing the file.
 
Back
Top