Advertisement
NAK

VB.NET Add Resource

NAK
Apr 18th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. HI…. OK gonna try and help you out with this… is difficult over the web tho…
  2.  
  3. So, in your project I can see that you have your ‘Button_Sound.wav’ file in a folder called 'Resources' and in your code you have ‘My.Resource. Button_Sound’ (snippet of your code there), that’s almost correct!!… you where on the right track BUT you need to do just one more thing before you can reference you’re *.wav files like that….
  4.  
  5. Follow these steps to create the Resource1.resx
  6.  
  7. · In the ‘Solution Explorer’ Right click your project [name] and select ‘Add->New Item’. So in your case you would right click on the node ‘Sports and Fitness’ then select ‘Add->New Item’…
  8. · In the Add New Item window that appears, select ‘Common Items’ in the left plane, then scroll down the list in the right plane to locate ‘Resource File’, select it and click the ‘Add’ button of the ‘Add New Item window’.
  9. · The default name for the file you just added is ‘Resource1.resx’ you can change this but you will have to modify your code accordingly…. I will refer to the default name ‘Resource1.resx’ from here
  10. · The ‘Resource1.resx’ can be anywhere in your project, it doesn’t have to be in a folder called ‘Resources’. After adding the new file, it should open up in the VS editor and there should be a new an icon appear in the ‘Solution Explorer’
  11.  
  12.  
  13. Ok so that should be the ‘Resource1.resx’ created; now you need to add some Resource… this is gonna be your Button_Sound.wav file….. I know it’s already in a folder in your project and that’s fine, you can leave it there for now….
  14.  
  15. OK so… Now to add the resource [Button_Sound.wav], follow these steps.
  16.  
  17.  
  18. · In the Visual Studio editor you should be looking at your newly created ‘Resource1.resx’ file. At the moment It’s just a blank white page with 5 or 6 buttons across the top (just under the file tabs), refer to the picture that I posted here.... you can see the Resource1.resx tab in my VS and the buttons.
  19. · http://www.flickr.com/photos/95021141@N04/8656939178/in/photostream/
  20. · In the VS editor, click on the button labelled ‘Add Resource’ [third button in across the top of the ‘Resource1.resx’ editor] this should open the ‘Add Existing files to Resource’ window.
  21. · Navigate to your ‘Button_Sound.wav’ file, select it and click ‘Open’…
  22.  
  23.  
  24. That’s it, Resource added, now you need to modify your code slightly…
  25.  
  26. Change this line in your code
  27.  
  28. My.Computer.Audio.Play(My.Resource.Button_Sound, AudioPlayMode.Background)
  29. To this.
  30. My.Computer.Audio.Play(My.Resources.Resource1.Button_Sound, AudioPlayMode.Background)
  31.  
  32. in the above [new] code see how i reference the 'Resource1' file... that's your 'link' between the code and the resource... see how close you where... you had the right idea but you were just missing that 'link'..
  33.  
  34. Remember, if you changed the name of the ‘Resource1.resx’ when you created it you will need to replace ‘Resource1’ in the above code with the name you gave the file….
  35.  
  36. That's it, all done, now when you run your code it should play the sound...
  37.  
  38. hope that helps...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement