■ GaugeControl 클래스를 사용해 환형 게이지를 동적으로 생성하는 방법을 보여준다.
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
using System.ComponentModel; using System.Drawing; using DevExpress.XtraEditors; using DevExpress.XtraGauges.Base; using DevExpress.XtraGauges.Core.Base; using DevExpress.XtraGauges.Core.Drawing; using DevExpress.XtraGauges.Core.Model; using DevExpress.XtraGauges.Win; using DevExpress.XtraGauges.Win.Base; using DevExpress.XtraGauges.Win.Gauges.Circular; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); ComponentResourceManager resourceManager = new ComponentResourceManager(typeof(MainForm)); #region 이미지 지시자 컴포넌트를 설정한다. ImageIndicatorComponent imageIndicatorComponent = new ImageIndicatorComponent(); imageIndicatorComponent.Name = "imageIndicatorComponent"; imageIndicatorComponent.Position = new PointF2D(125f, 125f); imageIndicatorComponent.ZOrder = -1000; imageIndicatorComponent.Image = Properties.Resources.flame; #endregion #region 레이블 컴포넌트를 설정한다. LabelComponent labelComponent = new LabelComponent(); labelComponent.Name = "labelComponent"; labelComponent.Position = new PointF2D(200f, 100f); labelComponent.Size = new SizeF(50F, 40F); labelComponent.AppearanceText.Font = new Font("Tahoma", 24F, FontStyle.Regular, GraphicsUnit.Pixel); labelComponent.Text = "95"; labelComponent.ZOrder = -1000; #endregion #region 아크 스케일 컴포넌트 1을 설정한다. ArcScaleComponent arcScaleComponent1 = new ArcScaleComponent(); arcScaleComponent1.Name = "arcScaleComponent1"; arcScaleComponent1.Center = new PointF2D(125f, 125f); arcScaleComponent1.RadiusX = 100f; arcScaleComponent1.RadiusY = 100f; arcScaleComponent1.StartAngle = 90f; arcScaleComponent1.EndAngle = 450f; arcScaleComponent1.AppearanceMinorTickmark.BorderBrush = new SolidBrushObject("Color:White"); arcScaleComponent1.AppearanceMinorTickmark.ContentBrush = new SolidBrushObject("Color:White"); arcScaleComponent1.AppearanceMajorTickmark.BorderBrush = new SolidBrushObject("Color:White"); arcScaleComponent1.AppearanceMajorTickmark.ContentBrush = new SolidBrushObject("Color:White"); arcScaleComponent1.AppearanceTickmarkText.TextBrush = new SolidBrushObject("Color:#484E5A"); arcScaleComponent1.AppearanceTickmarkText.Font = new Font("Tahoma", 8.5f); arcScaleComponent1.MinorTickCount = 0; arcScaleComponent1.MinorTickmark.ShapeOffset = -7f; arcScaleComponent1.MinorTickmark.ShapeType = TickmarkShapeType.Circular_Style16_2; arcScaleComponent1.MajorTickCount = 0; arcScaleComponent1.MajorTickmark.FormatString = "{0:F0}"; arcScaleComponent1.MajorTickmark.ShapeOffset = -14f; arcScaleComponent1.MajorTickmark.ShapeType = TickmarkShapeType.Circular_Style16_1; arcScaleComponent1.MajorTickmark.TextOrientation = LabelOrientation.LeftToRight; arcScaleComponent1.MinValue = 0f; arcScaleComponent1.MaxValue = 100f; arcScaleComponent1.Value = 50f; #endregion #region 아크 스케일 컴포넌트 2를 설정한다. ArcScaleComponent arcScaleComponent2 = new ArcScaleComponent(); arcScaleComponent2.Name = "arcScaleComponent2"; arcScaleComponent2.Center = new PointF2D(125f, 125f); arcScaleComponent2.RadiusX = 80f; arcScaleComponent2.RadiusY = 80f; arcScaleComponent2.StartAngle = 90f; arcScaleComponent2.EndAngle = 315f; arcScaleComponent2.AppearanceMinorTickmark.BorderBrush = new SolidBrushObject("Color:White"); arcScaleComponent2.AppearanceMinorTickmark.ContentBrush = new SolidBrushObject("Color:White"); arcScaleComponent2.AppearanceMajorTickmark.BorderBrush = new SolidBrushObject("Color:White"); arcScaleComponent2.AppearanceMajorTickmark.ContentBrush = new SolidBrushObject("Color:White"); arcScaleComponent2.AppearanceTickmarkText.TextBrush = new SolidBrushObject("Color:#484E5A"); arcScaleComponent2.AppearanceTickmarkText.Font = new Font("Tahoma", 8.5f); arcScaleComponent2.MinorTickCount = 0; arcScaleComponent2.MinorTickmark.ShapeOffset = -7F; arcScaleComponent2.MinorTickmark.ShapeType = TickmarkShapeType.Circular_Style16_2; arcScaleComponent2.MajorTickCount = 0; arcScaleComponent2.MajorTickmark.FormatString = "{0:F0}"; arcScaleComponent2.MajorTickmark.ShapeOffset = -14F; arcScaleComponent2.MajorTickmark.ShapeType = TickmarkShapeType.Circular_Style16_1; arcScaleComponent2.MajorTickmark.TextOrientation = LabelOrientation.LeftToRight; arcScaleComponent2.MinValue = 0f; arcScaleComponent2.MaxValue = 100f; arcScaleComponent2.Value = 50f; #endregion #region 아크 스타일 범위 막대 컴포넌트 1을 설정한다. ArcScaleRangeBarComponent arcScaleRangeBarComponent1 = new ArcScaleRangeBarComponent(); arcScaleRangeBarComponent1.Name = "arcScaleRangeBarComponent1"; arcScaleRangeBarComponent1.ZOrder = -10; arcScaleRangeBarComponent1.StartOffset = 80f; arcScaleRangeBarComponent1.EndOffset = 5f; arcScaleRangeBarComponent1.ArcScale = arcScaleComponent1; arcScaleRangeBarComponent1.ShowBackground = true; arcScaleRangeBarComponent1.RoundedCaps = false; #endregion #region 아크 스타일 범위 막대 컴포넌트 2를 설정한다. ArcScaleRangeBarComponent arcScaleRangeBarComponent2 = new ArcScaleRangeBarComponent(); arcScaleRangeBarComponent2.Name = "arcScaleRangeBarComponent2"; arcScaleRangeBarComponent2.ZOrder = -10; arcScaleRangeBarComponent2.StartOffset = 60f; arcScaleRangeBarComponent2.EndOffset = 5f; arcScaleRangeBarComponent2.ArcScale = arcScaleComponent2; arcScaleRangeBarComponent2.ShowBackground = true; arcScaleRangeBarComponent2.RoundedCaps = false; #endregion #region 환형 게이지를 설정한다. CircularGauge circularGauge = new CircularGauge(); circularGauge.Name = "circularGauge"; circularGauge.Bounds = new Rectangle(5, 5, 250, 250); circularGauge.Images.AddRange(new ImageIndicatorComponent[] { imageIndicatorComponent }); circularGauge.Labels.AddRange(new LabelComponent[] { labelComponent }); circularGauge.RangeBars.AddRange(new ArcScaleRangeBarComponent[] { arcScaleRangeBarComponent1, arcScaleRangeBarComponent2 }); circularGauge.Scales.AddRange(new ArcScaleComponent[] { arcScaleComponent1, arcScaleComponent2 }); #endregion #region 게이지 컨트롤을 설정한다. GaugeControl gaugeControl = new GaugeControl(); gaugeControl.Name = "gaugeControl"; gaugeControl.Location = new Point(100, 100); gaugeControl.Size = new Size(260, 260); gaugeControl.ColorScheme.Color = Color.FromArgb(255, 128, 0); gaugeControl.ColorScheme.TargetElements = TargetElement.RangeBar | TargetElement.ImageIndicator | TargetElement.Label; gaugeControl.Gauges.AddRange(new IGauge[] { circularGauge }); #endregion this.Controls.Add(gaugeControl); } #endregion } } |