When I wrote a program to play audio files (.wav, mp3) I need add some buttons for playing audio files. Unfortunately, .NET doesn’t have such buttons. As part of study on how to write my own controls, I create these audio buttons including Play, Pause, Rewind, Forward, Stop, ToEnd, ToStart. User can use them just as they are using the standard buttons supplied by VS .NET.
Using the code
Here is one example of how to use the code:
1. Use the project in your own solution: Download the source code, which is a project itself. Unzipped it into your solution folder (this would be better, but you can save them wherever you like) In your Solution Explorer in VS .NET, right click the solution and choose “Add” and “existing project…”. Choose AudioControls project from where ever you unzipped it, then click Open.
2. Add the AudioControls project as a reference to your own project: Right click your own project other than AudioControls project in Solution Explorer, choose “Add reference …” Then click the tab “Projects”, choose the project the click “Select”, then “OK”.
3. Add AudioButtons into your toolbox: At design mode, click your “Toolbox” and choose one of the tab (say My User Controls or whichever group you want the audiobuttons appear in) Right click the toolbox and choose “Add/Removing Items….” In “.NET Framework Components” tab click “Browse…”, in the new window browse for “AudioButtons.dll”, (normally should be under \bin\debug folder) then click “Open”
4. Now you can use AudioButtons just as you use standard buttons from VS .NET. In Properties window, you can find new properties “Audio Button”: ButtonType (ToStart, Rewind, Play, Pause, Stop, Forward, ToEnd), IconLocation and IconSize. They are self-explaining.
Further development
There are several properties could be added to the audio buttons, such as colors, gradient changing modes etc. You can easily add them by following the example of the code (property part). Hope these buttons are of some useful for you either in using them or in writing your own controls.
Thanks
Great thanks to Georgi Atanasov, whose article “Owner-draw button” were firstly studied before I started to write my own controls. Great thanks also goes to Carlos H. Perez and his UtilityLibrary.