Click here to Skip to main content
15,441,020 members
Articles / Programming Languages / C#
Posted 23 Oct 2006


202 bookmarked

Analog and LED Meter

Rate me:
Please Sign up or sign in to vote.
4.61/5 (39 votes)
10 Sep 2009CPOL6 min read
VU or Level meter, LED or Analog display
Sample Image - VuMeter_Demo.jpg


I've been searching a lot for an easy to use VU meter to use in a simple Audio player/recorder, but I haven't been lucky. I found some samples of LED meters, but not quite what I wanted.

It's good that I'm a bit stubborn, but unfortunately I'm also a complete beginner in C#, but that is the language I want to learn so I started my little project 2 weeks ago. This is the result.

The Code

I started out from a System.Windows.Forms.UserControl. I decided that the size should be calculated from the number of LED:s being used (I started with the LED, and added the analog this weekend), and added properties for LED size and spacing. The colors are user selectable in three different areas (up to 32 LED:s in each) with different settings for LED on and off so they could have a glow when idle.

BackColor is used for the border round the LED:s.

The LED:s are made up of filled rectangles, with a solid brush, easy to use and didn't take much time to get working, next I added the possibility to enable a PeakHold with selectable Hold time, and then I wanted to have a vertical version also. This solution is quite ugly, but it works ok.

As I wanted to use the LED:s for a VU meter, I wanted both analog and logarithmic scale (Log10) so that came next, and this was a bit tricky for me, but I made it and was very happy with my solution, but then suddenly I got the idea: But I want an old style analog meter, so I started searching, but found nothing (for free anyway), and the meters that had a decent price tag were ugly! I did find some extremely beautiful gauge meters, but almost 700$ is way beyond my budget!

So the only way was the hard way. I started last week, (on my spare time!) this was fun! I haven't learnt so much in many years, and I'm learning new things every day now, and I did get results!

I got the analog meter running over the weekend, but at a fixed size, and I couldn't make the background transparent, so I wasn't quite satisfied yet (I do not lie if I tell you that I had a lot of trouble getting the maths together for the analog meter). To solve the background, I found the example code in C# Help for a round button, set a region, and that did the trick, finally! But it would be nice to be able to have a different size, the TI-66 (I know its old, but it has nostalgic value for me) did some number crunching, and I began to change in the code, suddenly terrified that I hadn't made a backup before the changes, my test application didn't work anymore?!?! What to do, ctrl-z a wonderful key-combination, but when I found the error (I set the size to 0,0 by mistake) I just had to re-enter everything again. And now, tonight, I'm quite satisfied with my work, so the next thing was getting MP3 recording to work (don't now how yet, but I'm leaning towards BASS) so I could get some practical use of my wonderful meters.

Using the Code

I've done my best to make it easy to use. Here is a small explanation of how to use it.

First, drag the DLL to your Toolbox, then you could place a VuMeter on your Form.

To set it up the way you want it, go to the properties and look in Analog Meter, VU Meter and VU Meter - Colors. BackColor, Font and Size are also in use.

Analog Meter Properties

  • Analog Meter - True or False (default False) tells the meter if it should be LED or analog.
  • DialBackGround, is the color of the dial. DialTextNegativ, Positive and Zero is what color the text above the dial should have dependant on the value (text uses DialTextPositive).
  • NeedleColor and PeakNeedleColor are of course the color of the needle and peak indicator.
  • ShowDial Only - True or False (default False) removes the background around the meterdial so you could place it above some nice meter image or anything else you want.
  • ShowTextInDial - True or False (default True) tells if the text (values) should be shown in the dial, and the values are placed in TextInDial (a String array) and all the values are distributed in the upper part of the dial.
  • VuText is a text you could have in the dial (Default VU).

In the VU Meter category, you find more options:

  • Led1(2 and 3) Count number of LED:s in each area (default 6, 6 and 4) max value 32 for each area and minimum 0 (but there must be 1 LED in one of the areas) this is also the number of indicators that are shown in the analog dial.
  • LedSize (default 6;14) size of each led in pixels, same size is used in the analog meter so to get smaller "ticks" change the size here.
  • LedSpace (default 3) pixels between LED:s and also width of border around LED:s.
  • Level input level to meter determines number of LED:s to light or position of needle in analog view.
  • LevelMax (default 65535) Max input value also the level that turns on all the LED:s.
  • MeterScale Analog or Log10 (default Log10) what math to use when calculating Level.
  • PeakHold True or False (default True) if you should use PeakIndicator.
  • Peakms (default 1000) number of ms to hold peak value (max 10000).
  • VerticalBar True or False (default False) if you want a vertical LED-bar instead.
  • VU Meter - Colors, you figure it out for yourself ;)

Added October 25th

Section Analog

  • UseLedLight True or False (default False) if the Led:s in the dial should follow the needle.
  • ShowLedPeak True or False (default False) if the Peak indicator should be shown in Led also.
  • If you like this analog and digital meter, please give comments and feedback on the code and the component. If anyone out there could give me some help on how to record to a MP3 file from C#, I'd be happy to get some help.


  • October 22nd, 2006 - Article submitted
  • October 24th, 2006 - Updated, thanks to BruceN
  • October 25th, 2006 - Added extra features (Leds in Analog dialbar lights up)
  • February 21st, 2007 - Added properties-AssemblyInfo.cs to source code
  • December 1st, 2007 - Adapted the project to Visual C# Express 2008, new source code
  • September 10th, 2009 - Changed source to include all subfolders


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionPeak Hold Pin
Member 134633149-Jun-18 16:05
MemberMember 134633149-Jun-18 16:05 
Questionrecord output Pin
George Kashuba12-May-16 4:10
MemberGeorge Kashuba12-May-16 4:10 
QuestionGood Work! Pin
firewood00114-Nov-14 20:19
Memberfirewood00114-Nov-14 20:19 
QuestionVisual Studio 2008 under WIndows 7 Pin
AndersEtteplan10-Oct-13 3:09
MemberAndersEtteplan10-Oct-13 3:09 
GeneralMy vote of 4 Pin
Sergio Andrés Gutiérrez Rojas23-Sep-11 13:19
MemberSergio Andrés Gutiérrez Rojas23-Sep-11 13:19 
GeneralMy vote of 5 Pin
Dennis Betten2-Nov-10 22:34
MemberDennis Betten2-Nov-10 22:34 
QuestionHow to Use Peek like DEMO? Pin
jbahn19-Aug-10 21:54
Memberjbahn19-Aug-10 21:54 
AnswerRe: How to Use Peek like DEMO? Pin
Kent Andersson20-Aug-10 5:29
MemberKent Andersson20-Aug-10 5:29 
GeneralSome Changes Pin
ReymonARG18-Feb-10 21:59
MemberReymonARG18-Feb-10 21:59 
GeneralRe: Some Changes Pin
Kent Andersson19-Feb-10 9:05
MemberKent Andersson19-Feb-10 9:05 
GeneralRe: Some Changes Pin
ReymonARG19-Feb-10 10:25
MemberReymonARG19-Feb-10 10:25 
GeneralThank you !!! Pin
Riccardo.Bertoli27-Dec-09 11:33
MemberRiccardo.Bertoli27-Dec-09 11:33 
NewsProperties\Resources.resx is missing Pin
W5JDX23-Sep-09 13:32
MemberW5JDX23-Sep-09 13:32 
GeneralVS 2008 Pin
Pierre659-Sep-09 22:50
MemberPierre659-Sep-09 22:50 
GeneralRe: VS 2008 Pin
Kent Andersson10-Sep-09 6:39
MemberKent Andersson10-Sep-09 6:39 
GeneralRe: VS 2008 Pin
tlhIn`toq14-Sep-09 18:38
MembertlhIn`toq14-Sep-09 18:38 
AnswerRe: VS 2008 Pin
tlhIn`toq14-Sep-09 19:03
MembertlhIn`toq14-Sep-09 19:03 
GeneralRe: VS 2008 Pin
Kent Andersson14-Sep-09 19:37
MemberKent Andersson14-Sep-09 19:37 
GeneralRe: VS 2008 Pin
scaynet5-Apr-10 20:18
Memberscaynet5-Apr-10 20:18 
GeneralThank you! Pin
avarone14-Nov-08 10:25
Memberavarone14-Nov-08 10:25 
QuestionDo you have any info?? Pin
ejoee21-Aug-08 14:20
Memberejoee21-Aug-08 14:20 
Generalinput value less than LevelMax scale Pin
martinsvicente21-Jul-08 10:17
Membermartinsvicente21-Jul-08 10:17 
AnswerRe: input value less than LevelMax scale Pin
tlhIn`toq14-Sep-09 21:22
MembertlhIn`toq14-Sep-09 21:22 
GeneralLicense of ussage Pin
chuchuk28-Mar-08 11:02
Memberchuchuk28-Mar-08 11:02 
GeneralMissing files Pin
shark15465-Dec-07 5:41
Membershark15465-Dec-07 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.