Click here to Skip to main content
15,867,488 members
Articles / Multimedia / GDI+

An Improved Version of AGauge (A fast and performing gauge)

Rate me:
Please Sign up or sign in to vote.
4.93/5 (9 votes)
28 Aug 2012Zlib1 min read 80.7K   10.7K   37   29
An improved version of WinForms gauge control based on AGauge.

Introduction

This is an improved version of AGauge, a WinForm gauge control created by A.J Bauer. http://www.codeproject.com/Articles/17559/A-fast-and-performing-gauge. A few changes are made to original codes, details as below. 

AGauge_Bin.zip contains compiled DLL and a demo application. Please note that changes are not backward compatible with original code.

Improvements

Dynamic Gauge Label and Gauge Range

Properties for gauge label (previously known as CapText) and range are grouped into GaugeRanges and GaugeLabels which allow us to create any number of range and label as we wish. Range and label can be edited either from code or using the collection editor from the properties window.

C#
[System.ComponentModel.Browsable(true),
System.ComponentModel.Category("AGauge"),
System.ComponentModel.Description("Gauge Ranges.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public AGaugeRangeCollection GaugeRanges { get { return _GaugeRanges; } }
private AGaugeRangeCollection _GaugeRanges;

[System.ComponentModel.Browsable(true),
System.ComponentModel.Category("AGauge"),
System.ComponentModel.Description("Gauge Labels.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public AGaugeLabelCollection GaugeLabels { get { return _GaugeLabels; } }
private AGaugeLabelCollection _GaugeLabels;

Image 1

Besides, each label can use different Font settings since label is an instance of AGaugeLabel.

Added NeedleType Enumeration

AGauge control has two different type of needle design selectable from NeedleType property. Type of NeedleType property waschanged from Int32 (0 or 1) to enumeration type (NeedleType.Advance or NeedleType.Simple) to avoid invalid entry from user.

Image 2

Events

Update ValueInRangeChangedEvent

ValueInRangeChangedDelegate was changed to ValueInRangeChangedEvent to allow multiple subscriptions. The event is changed to trigger only if value is entering or leaving a defined range. Besides, ValueInRangeChangedEventArgs was updated to hold current range and gauge value. 

C#
[Description("This event is raised if the value is entering or leaving defined range.")]
public event EventHandler<ValueInRangeChangedEventArgs> ValueInRangeChanged;
private void OnValueInRangeChanged(AGaugeRange range, Single value)
{
    EventHandler<ValueInRangeChangedEventArgs> e = ValueInRangeChanged;
    if (e != null) e(this, new ValueInRangeChangedEventArgs(range, value, range.InRange));
}

/// <summary>
/// Event argument for <see cref="ValueInRangeChanged"/> event.
/// </summary>
public class ValueInRangeChangedEventArgs : EventArgs
{
    /// <summary>
    /// Affected GaugeRange
    /// </summary>
    public AGaugeRange Range { get; private set; }
    /// <summary>
    /// Gauge Value
    /// </summary>
    public Single Value { get; private set; }
    /// <summary>
    /// True if value is within current range.
    /// </summary>
    public bool InRange { get; private set; }
    public ValueInRangeChangedEventArgs(AGaugeRange range, Single value, bool inRange)
    {
        this.Range = range;
        this.Value = value;
        this.InRange = inRange;
    }
}

Added ValueChangedEvent

The ValueChanged event is added to notify user whenever gauge value is updated. Note that attempting to set gauge value out of defined gauge range will not trigger this event.

C#
[Description("This event is raised when gauge value changed.")]
public event EventHandler ValueChanged;
private void OnValueChanged()
{
    EventHandler e = ValueChanged;
    if (e != null) e(this, null);
}

History 

  • 28/08/2012: Initial release (version 2.0.0).

License

This article, along with any associated source code and files, is licensed under The zlib/libpng License


Written By
Technical Lead
Malaysia Malaysia
Official Page: www.codearteng.com

Comments and Discussions

 
QuestionVery Nice, Capable Gauge- Using in VB.Net 2008 Pin
YorkshireCap9-Nov-20 8:08
YorkshireCap9-Nov-20 8:08 
AnswerRe: Very Nice, Capable Gauge- Using in VB.Net 2008 Pin
Code Artist12-Nov-20 1:35
professionalCode Artist12-Nov-20 1:35 
PraiseGood work Code Artist! Pin
Implements Master Yoda31-May-18 23:46
Implements Master Yoda31-May-18 23:46 
QuestionAGauge Update Pin
Code Artist21-Apr-18 22:47
professionalCode Artist21-Apr-18 22:47 
QuestionSmall Range Min Step Pin
Member 1373067316-Mar-18 11:15
Member 1373067316-Mar-18 11:15 
AnswerRe: Small Range Min Step Pin
Member 1373067316-Mar-18 12:49
Member 1373067316-Mar-18 12:49 
QuestionAgauge does not display properly Pin
Member 130262968-Jan-18 16:41
Member 130262968-Jan-18 16:41 
I'm using Windows 10 and running Visual Studio 2017. When I add the gauge to the editor it appears fine but when I run the program only the top left quadrant of the gauge is visible. When I enlarge the bounding box for the control it seems to fix the problem, however in order to do this the bounding box takes up 3/4 of the form. As a result any buttons that are put next to the gauge itself inside the bounding box are rearranged and appear over the center of the gauge.
form1.designer.cs is as follows

namespace WindowsFormsApp2
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.aGauge1 = new System.Windows.Forms.AGauge();
            this.SuspendLayout();
            // 
            // aGauge1
            // 
            this.aGauge1.BaseArcColor = System.Drawing.Color.Gray;
            this.aGauge1.BaseArcRadius = 80;
            this.aGauge1.BaseArcStart = 135;
            this.aGauge1.BaseArcSweep = 270;
            this.aGauge1.BaseArcWidth = 2;
            this.aGauge1.Center = new System.Drawing.Point(100, 100);
            this.aGauge1.Location = new System.Drawing.Point(40, 13);
            this.aGauge1.MaxValue = 400F;
            this.aGauge1.MinValue = -100F;
            this.aGauge1.Name = "aGauge1";
            this.aGauge1.NeedleColor1 = System.Windows.Forms.AGaugeNeedleColor.Gray;
            this.aGauge1.NeedleColor2 = System.Drawing.Color.DimGray;
            this.aGauge1.NeedleRadius = 80;
            this.aGauge1.NeedleType = System.Windows.Forms.NeedleType.Advance;
            this.aGauge1.NeedleWidth = 2;
            this.aGauge1.ScaleLinesInterColor = System.Drawing.Color.Black;
            this.aGauge1.ScaleLinesInterInnerRadius = 73;
            this.aGauge1.ScaleLinesInterOuterRadius = 80;
            this.aGauge1.ScaleLinesInterWidth = 1;
            this.aGauge1.ScaleLinesMajorColor = System.Drawing.Color.Black;
            this.aGauge1.ScaleLinesMajorInnerRadius = 70;
            this.aGauge1.ScaleLinesMajorOuterRadius = 80;
            this.aGauge1.ScaleLinesMajorStepValue = 50F;
            this.aGauge1.ScaleLinesMajorWidth = 2;
            this.aGauge1.ScaleLinesMinorColor = System.Drawing.Color.Gray;
            this.aGauge1.ScaleLinesMinorInnerRadius = 75;
            this.aGauge1.ScaleLinesMinorOuterRadius = 80;
            this.aGauge1.ScaleLinesMinorTicks = 9;
            this.aGauge1.ScaleLinesMinorWidth = 1;
            this.aGauge1.ScaleNumbersColor = System.Drawing.Color.Black;
            this.aGauge1.ScaleNumbersFormat = null;
            this.aGauge1.ScaleNumbersRadius = 95;
            this.aGauge1.ScaleNumbersRotation = 0;
            this.aGauge1.ScaleNumbersStartScaleLine = 0;
            this.aGauge1.ScaleNumbersStepScaleLines = 1;
            this.aGauge1.Size = new System.Drawing.Size(430, 391);
            this.aGauge1.TabIndex = 0;
            this.aGauge1.Text = "aGauge1";
            this.aGauge1.Value = 0F;
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(14F, 29F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(933, 416);
            this.Controls.Add(this.aGauge1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.AGauge aGauge1;
    }
}

AnswerRe: Agauge does not display properly Pin
Code Artist11-Jan-18 3:42
professionalCode Artist11-Jan-18 3:42 
Questiongauge ranges Pin
Member 112647066-Nov-16 15:44
Member 112647066-Nov-16 15:44 
QuestionUsing gauges Pin
Member 1262907911-Jul-16 4:15
Member 1262907911-Jul-16 4:15 
AnswerRe: Using gauges Pin
Code Artist11-Jul-16 5:52
professionalCode Artist11-Jul-16 5:52 
GeneralRe: Using gauges Pin
Member 1262907911-Jul-16 7:32
Member 1262907911-Jul-16 7:32 
GeneralRe: Using gauges Pin
Code Artist12-Jul-16 2:25
professionalCode Artist12-Jul-16 2:25 
GeneralRe: Using gauges Pin
Member 1262907912-Jul-16 2:59
Member 1262907912-Jul-16 2:59 
QuestionShowing error AGauge.dll is not a microsoft .NET module Pin
shah_kushal14-Mar-16 1:44
shah_kushal14-Mar-16 1:44 
QuestionIncrement label for m_ScaleLinesInterStepValue Pin
nuimpress22-Sep-15 20:07
nuimpress22-Sep-15 20:07 
AnswerRe: Increment label for m_ScaleLinesInterStepValue Pin
Code Artist23-Sep-15 4:24
professionalCode Artist23-Sep-15 4:24 
QuestionResize Pin
Francis Apel1-Nov-13 8:01
Francis Apel1-Nov-13 8:01 
AnswerRe: Resize Pin
Code Artist2-Nov-13 19:49
professionalCode Artist2-Nov-13 19:49 
QuestionDual Scales and transparent background Pin
George papas15-Oct-12 14:38
George papas15-Oct-12 14:38 
Questiongauge with two needle Pin
Member 87699612-Oct-12 21:04
Member 87699612-Oct-12 21:04 
AnswerRe: gauge with two needle Pin
Code Artist3-Oct-12 3:07
professionalCode Artist3-Oct-12 3:07 
GeneralMy vote of 5 Pin
Opata Chibueze16-Sep-12 14:39
Opata Chibueze16-Sep-12 14:39 
GeneralRe: My vote of 5 Pin
Code Artist17-Sep-12 2:37
professionalCode Artist17-Sep-12 2:37 
GeneralMy vote of 5 Pin
Christian Amado28-Aug-12 12:49
professionalChristian Amado28-Aug-12 12:49 

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.