Programming Tutorial On The Way

free online programming resource on dotnet, csharp, web related topics

Play a Simple Beep

The .NET Framework does not include any managed classes for playing audio files or even for playing the system beep sound. However, you can easily bridge this gap using the Win32 API or Visual Basic .NET, which provides a legacy Beep function that’s exposed through the Microsoft.VisualBasic.Interaction class. In the latter case, you must add a reference to the Microsoft.VisualBasic.dll assembly (which is included with all versions of the .NET Framework).

The following example uses both the Beep API function and the Visual Basic Beep function. Notice that the API function actually uses the computer’s internal speaker and plays a tone with the indicated frequency (in hertz, ranging from 37 to 32,767) and duration (in milliseconds). This won’t produce any sound if the computer does not have an internal speaker. The Visual Basic Beep function, on the other hand, plays the standard system-defined beep sound event (which is a WAV audio file). This won’t produce any sound if the computer doesn’t have a sound card, if the sound card is not connected to external speakers, or if Windows is configured (via the Sounds and Audio Devices section of the Control Panel) to not play sounds.
Read the rest of this entry »

Popularity: 5% [?]

To get the preview of all available fonts installed in your computer, you can create a simple windows application for that. Basically, you need to create a new instance of the System.Drawing.Text.InstalledFontCollection class, which contains a collection of FontFamily objects representing all the installed fonts.

The InstalledFontCollection class allows you to retrieve information about currently installed fonts. The following code shows a form that iterates through the font collection when it’s first created. Every time it finds a font, it creates a new label that will display the font name in the given font face (at a size of 14 point). The label is added to a scrollable panel, allowing the user to scroll through the list of available fonts.
Read the rest of this entry »

Popularity: 3% [?]