Results 1 to 4 of 4

Thread: Help with PictureBoxes

  1. #1
    mayjay is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2011
    Posts
    2
    Reputation
    0

    Help with PictureBoxes

    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!

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    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.

  3. #3
    mayjay is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Nov 2011
    Posts
    2
    Reputation
    0
    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.

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,225
    Reputation
    2370
    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.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking