Another idea would be to have the resource names the same as the button names without the word "Button" in them.
For example, I have two buttons and two resources.
Button names:
cButton
c_sharpButton
Audio Resource names:
c
c_sharp
Notice this one button Handles cButton.Click and c_sharpButton.Click, and any other button.clicks I add to it.
Code:Private Sub cButton_Click(sender As System.Object, e As System.EventArgs) _ Handles cButton.Click, c_sharpButton.Click ' get name of this button and remove "Button" from the name Dim keyname As String = DirectCast(sender, Button).Name keyname = keyname.Replace("Button", "") ' use the keyname to get the resource Dim mysound = My.Resources.ResourceManager.GetStream(keyname) ' play it My.Computer.Audio.Play(mysound, AudioPlayMode.Background) End Sub




Reply With Quote