Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Collapse]Gauges
   [Expand]Getting Started
   [Expand]Concepts
   [Expand]Design-Time Features
   [Collapse]Examples
     How to: Add and Customize Gauge Animation
     How To: Bind a Gauge Control to a Data Source
     How to: Bind a Gauge Control to a Data Source at Runtime
     How to: Create a Circular Gauge (Design-time)
     How to: Create a Circular Gauge (Runtime)
     How To: Create a Digital Gauge (Design-time)
     How To: Create a Digital Gauge (Runtime)
     How To: Create a Gauge From Scratch (Runtime)
     How To: Create a Linear Gauge (Design-time)
     How To: Create a Linear Gauge (Runtime)
     How To: Create a State Indicator Gauge (Design-time)
     How To: Create a State Indicator Gauge (Runtime)
     How To: Custom Draw a Gauge Control
     How to: Move Value Indicators at Runtime
     How To: Use Gauges for In-Place Editing
   [Expand]Product Information
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How To: Create a Gauge From Scratch (Runtime)

This example illustrates how to create the same gauge as in the Creating a Gauge from Scratch walkthrough, but entirely in code. Unlike other 'How to' examples that make use of the AddDefaultElement method called for a required gauge (e.g., the CircularGauge.AddDefaultElements method), the following code does not create any predefined elements. Instead, all elements are created and customized manually.

There are two ways of adding gauge elements manually. The most convenient way is to use the desired Add... methods from code (e.g., CircularGauge.AddNeedle, LinearGauge.AddScale, DigitalGauge.AddBackgroundLayer, etc.). Not only do these methods add related gauge elements to the gauge, but they also automatically customize these elements according to the most frequently used scenarios. For instance, calling the AddScale method will result in adding a scale, whose tickmarks are already formatted to display integer values. Thus, you won't need to call set the MajorTickmark.FormatString property manually.

The alternate approach is to instantiate objects of desired classes (ArcScaleComponent, LinearScaleMarkerComponent, DigitalBackgroundLayerComponent, etc.), then manually specify their settings and add to the related collections of your gauge (e.g., the CircularGauge.Needles collection that holds all needles owned by this gauge). When following this approach, make sure to set all significant properties manually. For instance, you will need to specify names for all your manually created elements.

Whichever approach you choose, wrap any code that customizes gauge elements in the BeginUpdate\EndUpdate method pair. By doing so, you avoid excessive element visual updates.

How would you rate this topic?​​​​​​​