■ 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
using System.Drawing; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; using DevExpress.XtraGauges.Base; using DevExpress.XtraGauges.Core.Base; using DevExpress.XtraGauges.Core.Drawing; using DevExpress.XtraGauges.Core.Model; using DevExpress.XtraGauges.Core.Primitive; using DevExpress.XtraGauges.Win; using DevExpress.XtraGauges.Win.Gauges.Circular; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 게이지 컨트롤 /// </summary> private GaugeControl gaugeControl; /// <summary> /// 아크 스케일 컴포넌트 /// </summary> private ArcScaleComponent arcScaleComponent; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); #region 게이지 컨트롤을 설정한다. this.gaugeControl = new GaugeControl(); this.gaugeControl.Parent = this; this.gaugeControl.Location = new Point(50, 50); this.gaugeControl.Size = new Size(400, 400); this.gaugeControl.BackColor = Color.Transparent; this.gaugeControl.BorderStyle = BorderStyles.NoBorder; #endregion #region 환형 게이지를 설정한다. CircularGauge circularGauge = this.gaugeControl.AddCircularGauge(); circularGauge.AddDefaultElements(); #endregion #region 아크 스케일 배경 레이어를 설정한다. ArcScaleBackgroundLayer arcScaleBackgroundLayer = circularGauge.BackgroundLayers[0]; arcScaleBackgroundLayer.ShapeType = BackgroundLayerShapeType.CircularFull_Style10; #endregion #region 아크 스케일 컴포넌트를 설정한다. this.arcScaleComponent = circularGauge.Scales[0]; this.arcScaleComponent.MinValue = 0; this.arcScaleComponent.MaxValue = 100; this.arcScaleComponent.Value = 25; this.arcScaleComponent.AppearanceTickmarkText.Font = new Font("Tahoma", 10f); this.arcScaleComponent.AppearanceTickmarkText.TextBrush = new SolidBrushObject(Color.White); this.arcScaleComponent.MajorTickCount = 11; this.arcScaleComponent.MajorTickmark.FormatString = "{0:F0}"; this.arcScaleComponent.MajorTickmark.ShapeType = TickmarkShapeType.Circular_Style2_2; this.arcScaleComponent.MajorTickmark.ShapeOffset = -10; this.arcScaleComponent.MajorTickmark.TextOffset = -20; this.arcScaleComponent.MajorTickmark.AllowTickOverlap = true; this.arcScaleComponent.MinorTickCount = 3; this.arcScaleComponent.MinorTickmark.ShapeType = TickmarkShapeType.Circular_Style2_1; #endregion #region 아크 스케일 바늘 컴포넌트를 설정한다. ArcScaleNeedleComponent arcScaleNeedleComponent = circularGauge.Needles[0]; arcScaleNeedleComponent.ShapeType = NeedleShapeType.CircularFull_Style3; #endregion #region 아크 스케일 스핀들 캡 컴포넌트를 설정한다. ArcScaleSpindleCapComponent arcScaleSpindleCapComponent = arcScaleSpindleCapComponent = new ArcScaleSpindleCapComponent(); arcScaleSpindleCapComponent.Name = "arcScaleSpindleCapComponent"; arcScaleSpindleCapComponent.ArcScale = this.arcScaleComponent; arcScaleSpindleCapComponent.Size = new SizeF(42F, 42F); arcScaleSpindleCapComponent.ZOrder = -1000; arcScaleSpindleCapComponent.Shader = new OpacityShader(); circularGauge.SpindleCaps.Add(arcScaleSpindleCapComponent); #endregion this.gaugeControl.MouseDown += gaugeControl_MouseDown; this.gaugeControl.MouseMove += gaugeControl_MouseMove; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 게이지 컨트롤 마우스 DOWN 처리하기 - gaugeControl_MouseDown(sender, e) /// <summary> /// 게이지 컨트롤 마우스 DOWN 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gaugeControl_MouseDown(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Left) { CalculateMouseValue(this.gaugeControl, this.arcScaleComponent, e); } } #endregion #region 게이지 컨트롤 마우스 이동시 처리하기 - gaugeControl_MouseMove(sender, e) /// <summary> /// 게이지 컨트롤 마우스 이동시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gaugeControl_MouseMove(object sender, MouseEventArgs e) { CheckCursor(this.gaugeControl as IGaugeContainer, e); if(e.Button == MouseButtons.Left) { CalculateMouseValue(this.gaugeControl, this.arcScaleComponent, e); } } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 커서 체크하기 - CheckCursor(gaugeContainer, e) /// <summary> /// 커서 체크하기 /// </summary> /// <param name="gaugeContainer">게이지 컨테이너</param> /// <param name="e">이벤트 인자</param> private void CheckCursor(IGaugeContainer gaugeContainer, MouseEventArgs e) { BasePrimitiveHitInfo hitInfo = gaugeContainer.CalcHitInfo(e.Location); Cursor cursor = (hitInfo.Element != null && !hitInfo.Element.IsComposite) ? Cursors.Hand : Cursors.Default; if(((Control)gaugeContainer).Cursor != cursor) { ((Control)gaugeContainer).Cursor = cursor; } } #endregion #region 마우스 값 계산하기 - CalculateMouseValue(container, convertibleScaleEx, e) /// <summary> /// 마우스 값 계산하기 /// </summary> /// <param name="gaugeContainer">게이지 컨테이너 인터페이스</param> /// <param name="convertibleScaleEx">변환 가능 스케일 확장 인터페이스</param> /// <param name="e">이벤트 인자</param> private void CalculateMouseValue(IGaugeContainer gaugeContainer, IConvertibleScaleEx convertibleScaleEx, MouseEventArgs e) { BasePrimitiveHitInfo hitInfo = gaugeContainer.CalcHitInfo(e.Location); if(hitInfo.Element != null && !hitInfo.Element.IsComposite) { PointF point = MathHelper.PointToModelPoint(convertibleScaleEx as IElement<IRenderableElement>, new PointF(e.X, e.Y)); float percent = convertibleScaleEx.PointToPercent(point); convertibleScaleEx.Value = convertibleScaleEx.PercentToValue(percent); } } #endregion } } |