Example E3955
Visible to All Users

WinForms Gauge - Appearance customization (custom draw)

This example handles the CustomDrawElement event to customize the appearance of the following gauge UI elements:

WinForms Gauge Appearance Customization

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

XtraGauges_CustomDraw/Form1.cs(vb)
C#
using System; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraGauges.Core.Primitive; using DevExpress.XtraGauges.Core.Model; namespace XtraGauges_CustomDraw { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Timer timer; int animationLockCounter = 0; bool enableCustomDraw = false; private void arcScaleBackgroundLayerComponent1_CustomDrawElement(object sender, CustomDrawElementEventArgs e) { if (enableCustomDraw) { RectangleF bounds = RectangleF.Inflate(e.Info.BoundBox, -15, -15); e.Context.Graphics.FillEllipse(Brushes.Black, bounds); bounds.Inflate(-2, -2); e.Context.Graphics.SetClip(new RectangleF(bounds.Left + bounds.Width * 0.5f, bounds.Top, bounds.Width * 0.5f, bounds.Height)); e.Context.Graphics.FillEllipse(Brushes.White, bounds); e.Context.Graphics.ResetClip(); e.Context.Graphics.FillEllipse(Brushes.White, new RectangleF(bounds.Left + +bounds.Width * 0.25f, bounds.Top, bounds.Width * 0.5f, bounds.Height * 0.5f)); e.Context.Graphics.FillEllipse(Brushes.Black, new RectangleF(bounds.Left + bounds.Width * 0.25f, bounds.Top + bounds.Height * 0.5f, bounds.Width * 0.5f, bounds.Height * 0.5f)); e.Handled = true; } } private void arcScaleNeedleComponent1_CustomDrawElement(object sender, CustomDrawElementEventArgs e) { if (enableCustomDraw) { e.Context.Graphics.FillEllipse(Brushes.White, new RectangleF(50, 112.5f, 25, 25)); e.Context.Graphics.FillEllipse(Brushes.Black, new RectangleF(175, 112.5f, 25, 25)); e.Handled = true; } } private void arcScaleComponent1_CustomDrawElement(object sender, CustomDrawElementEventArgs e) { if (enableCustomDraw) e.Handled = true; } private void checkEdit1_CheckStateChanged(object sender, EventArgs e) { enableCustomDraw = checkEdit1.Checked; arcScaleBackgroundLayerComponent1.Self.ResetCache(CacheKeys.RenderedImage); gaugeControl1.Refresh(); } private void Form1_Load(object sender, EventArgs e) { timer = new Timer(); timer.Interval = 150; timer.Tick += new EventHandler(OnTimerTick); timer.Start(); } void OnTimerTick(object sender, EventArgs e) { if (animationLockCounter > 0) return; animationLockCounter++; arcScaleComponent1.Value = AnimateScaleValue(arcScaleComponent1, 0.05f); animationLockCounter--; } float AnimateScaleValue(IBaseScale scale, float factor) { Random random = new Random(DateTime.Now.Millisecond); float deviation = ((float)random.NextDouble() - scale.Percent); return (scale.Value + (scale.ScaleLength * factor) * deviation); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.