첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요