Click here to Skip to main content
12,754,090 members (29,920 online)
Click here to Skip to main content
Add your own
alternative version

Stats

27.9K views
4.8K downloads
27 bookmarked
Posted 28 Aug 2012

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

, 28 Aug 2012 Zlib
Rate this:
Please Sign up or sign in to vote.
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.

[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;

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.

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. 

[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.

[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

Share

About the Author

Code Artist
Technical Lead
Malaysia Malaysia
Official Page: www.codearteng.com

You may also be interested in...

Pro
Pro

Comments and Discussions

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

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 28 Aug 2012
Article Copyright 2012 by Code Artist
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid