728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGauges.Core.Primitive;
using DevExpress.XtraGauges.Core.Model;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 타이머
/// </summary>
private Timer timer;
/// <summary>
/// 애니메이션 잠금 카운터
/// </summary>
private int animationLockCounter = 0;
/// <summary>
/// 커스텀 그리기 여부
/// </summary>
private bool customDraw = false;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.Load += Form_Load;
this.arcScaleNeedleComponent.CustomDrawElement += arcScaleNeedleComponent_CustomDrawElement;
this.arcScaleBackgroundLayerComponent.CustomDrawElement += arcScaleBackgroundLayerComponent_CustomDrawElement;
this.arcScaleComponent.CustomDrawElement += arcScaleComponent_CustomDrawElement;
this.checkEdit.CheckStateChanged += checkEdit_CheckStateChanged;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
this.timer = new Timer();
this.timer.Interval = 150;
this.timer.Tick += timer_Tick;
this.timer.Start();
}
#endregion
#region 아크 스케일 컴포넌트 요소 커스텀 그리기 - arcScaleComponent_CustomDrawElement(sender, e)
/// <summary>
/// 아크 스케일 컴포넌트 요소 커스텀 그리기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void arcScaleComponent_CustomDrawElement(object sender, CustomDrawElementEventArgs e)
{
if(this.customDraw)
{
e.Handled = true;
}
}
#endregion
#region 아크 스케일 배경 레이어 컴포넌트 요소 커스텀 그리기 - arcScaleBackgroundLayerComponent_CustomDrawElement(sender, e)
/// <summary>
/// 아크 스케일 배경 레이어 컴포넌트 요소 커스텀 그리기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void arcScaleBackgroundLayerComponent_CustomDrawElement(object sender, CustomDrawElementEventArgs e)
{
if(this.customDraw)
{
RectangleF rectangle = RectangleF.Inflate(e.Info.BoundBox, -15, -15);
e.Context.Graphics.FillEllipse(Brushes.Black, rectangle);
rectangle.Inflate(-2, -2);
e.Context.Graphics.SetClip
(
new RectangleF
(
rectangle.Left + rectangle.Width * 0.5f,
rectangle.Top,
rectangle.Width * 0.5f,
rectangle.Height
)
);
e.Context.Graphics.FillEllipse(Brushes.White, rectangle);
e.Context.Graphics.ResetClip();
e.Context.Graphics.FillEllipse
(
Brushes.White,
new RectangleF
(
rectangle.Left + rectangle.Width * 0.25f,
rectangle.Top,
rectangle.Width * 0.5f,
rectangle.Height * 0.5f
)
);
e.Context.Graphics.FillEllipse
(
Brushes.Black,
new RectangleF
(
rectangle.Left + rectangle.Width * 0.25f,
rectangle.Top + rectangle.Height * 0.5f,
rectangle.Width * 0.5f,
rectangle.Height * 0.5f
)
);
e.Handled = true;
}
}
#endregion
#region 아크 스케일 바늘 컴포넌트 요소 커스텀 그리기 - arcScaleNeedleComponent_CustomDrawElement(sender, e)
/// <summary>
/// 아크 스케일 바늘 컴포넌트 요소 커스텀 그리기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void arcScaleNeedleComponent_CustomDrawElement(object sender, CustomDrawElementEventArgs e)
{
if(this.customDraw)
{
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;
}
}
#endregion
#region 체크 에디터 체크 상태 변경시 처리하기 - checkEdit_CheckStateChanged(sender, e)
/// <summary>
/// 체크 에디터 체크 상태 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void checkEdit_CheckStateChanged(object sender, EventArgs e)
{
this.customDraw = this.checkEdit.Checked;
this.arcScaleBackgroundLayerComponent.Self.ResetCache(CacheKeys.RenderedImage);
this.gaugeControl.Refresh();
}
#endregion
#region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary>
/// 타이머 틱 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void timer_Tick(object sender, EventArgs e)
{
if(this.animationLockCounter > 0)
{
return;
}
this.animationLockCounter++;
this.arcScaleComponent.Value = AnimateScaleValue(this.arcScaleComponent, 0.05f);
this.animationLockCounter--;
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 스케일 값 애니메이션 처리하기 - AnimateScaleValue(baseScale, factor)
/// <summary>
/// 스케일 값 애니메이션 처리하기
/// </summary>
/// <param name="baseScale">베이스 스케일 인터페이스</param>
/// <param name="factor">인자</param>
/// <returns>스케일 값</returns>
private float AnimateScaleValue(IBaseScale baseScale, float factor)
{
Random random = new Random(DateTime.Now.Millisecond);
float deviation = ((float)random.NextDouble() - baseScale.Percent);
return (baseScale.Value + (baseScale.ScaleLength * factor) * deviation);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'DevExpress > WinForm' 카테고리의 다른 글
[DEVEXPRESS/WINFORM] ShapefileDataAdapter 클래스 : 벡터 데카르트(Vector Cartesian) 맵 생성하기 (0) | 2020.06.15 |
---|---|
[DEVEXPRESS/WINFORM] BingMapDataProvider 클래스 : 이미지 공급자 연결하기 (0) | 2020.06.15 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 그리드 내장 에디터로 게이지 사용하기 (0) | 2020.06.14 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 그리드 내장 에디터로 게이지 사용하기 (0) | 2020.06.14 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 마우스를 사용해 값 지시자 이동시키기 (0) | 2020.06.14 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 상태 지시자 게이지 사용하기 (0) | 2020.06.14 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 선형 게이지 생성하기 (0) | 2020.06.14 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 디지털 게이지 생성하기 (0) | 2020.06.14 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 환형 게이지 동적 생성하기 (0) | 2020.06.13 |
[DEVEXPRESS/WINFORM] GaugeControl 클래스 : 게이지 스타일 적용하기 (0) | 2020.06.13 |
댓글을 달아 주세요