■ UserControl 클래스 : 환형 진행바 사용하기
------------------------------------------------------------------------------------------------------------------------
▶ CircularProgressBar.cs
using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms;
namespace TestProject { /// <summary> /// 환형 진행바 /// </summary> public partial class CircularProgressBar : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary> /// 펜 너비 /// </summary> private int penWidth;
/// <summary> /// 배경 펜 색상 /// </summary> private Color backgroundPenColor;
/// <summary> /// 전경 펜 색상 /// </summary> private Color foregroundPenColor;
/// <summary> /// 배경 펜 /// </summary> private Pen backgroundPen;
/// <summary> /// 전경 펜 /// </summary> private Pen foregroundPen;
/// <summary> /// 최대 값 /// </summary> private int maximumValue;
/// <summary> /// 값 /// </summary> private int value;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 펜 너비 - PenWidth
/// <summary> /// 펜 너비 /// </summary> [Category("CircularProgressBar")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description("펜 너비")] public int PenWidth { get { return this.penWidth; } set { this.penWidth = value;
this.backgroundPen = new Pen(this.backgroundPenColor, this.penWidth); this.foregroundPen = new Pen(this.foregroundPenColor, this.penWidth);
Invalidate(); } }
#endregion #region 배경 펜 색상 - BackgroundPenColor
/// <summary> /// 배경 펜 색상 /// </summary> [Category("CircularProgressBar")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description("펜 색상")] public Color BackgroundPenColor { get { return this.backgroundPenColor; } set { this.backgroundPenColor = value;
this.backgroundPen = new Pen(this.backgroundPenColor, this.penWidth);
Invalidate(); } }
#endregion #region 전경 펜 색상 - ForegroundPenColor
/// <summary> /// 전경 펜 색상 /// </summary> [Category("CircularProgressBar")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description("전경 펜 색상")] public Color ForegroundPenColor { get { return foregroundPenColor; } set { foregroundPenColor = value;
this.foregroundPen = new Pen(this.foregroundPenColor, this.penWidth);
Invalidate(); } }
#endregion #region 최대 값 - MaximumValue
/// <summary> /// 최대 값 /// </summary> [Category("CircularProgressBar")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description("최대 값")] public int MaximumValue { get { return this.maximumValue; } set { this.maximumValue = value;
Invalidate(); } }
#endregion #region 값 - Value
/// <summary> /// 값 /// </summary> [Category("CircularProgressBar")] [Browsable(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description("값")] public int Value { get { return this.value; } set { this.value = value;
Invalidate(); } }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - CircularProgressBar()
/// <summary> /// 생성자 /// </summary> public CircularProgressBar() { InitializeComponent();
this.penWidth = 10; this.backgroundPenColor = Color.LightGray; this.backgroundPen = new Pen(this.backgroundPenColor, this.penWidth); this.foregroundPenColor = Color.Orange; this.foregroundPen = new Pen(this.foregroundPenColor, this.penWidth); this.maximumValue = 100; this.value = 0;
Load += UserControl_Load; Paint += UserControl_Paint; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event
#region 사용자 컨트롤 로드시 처리하기 - UserControl_Load(sender, e)
/// <summary> /// 사용자 컨트롤 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void UserControl_Load(object sender, EventArgs e) { DoubleBuffered = true;
Invalidate(); }
#endregion #region 사용자 컨트롤 페인트시 처리하기 - UserControl_Paint(sender, e)
/// <summary> /// 사용자 컨트롤 페인트시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void UserControl_Paint(object sender, PaintEventArgs e) { Graphics graphics = e.Graphics;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.DrawEllipse(this.backgroundPen, 10, 10, Width - 20,Height - 20);
int progressValue = GetProgresValue(this.value, this.maximumValue);
graphics.DrawArc(this.foregroundPen, 10, 10, Width - 20, Height - 20 , -90, progressValue); }
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 진행 값 구하기 - GetProgresValue(value , maximumValue)
/// <summary> /// 진행 값 구하기 /// </summary> /// <param name="value">값</param> /// <param name="maximumValue">최대 값</param> /// <returns>진행</returns> private int GetProgresValue(int value , int maximumValue) { return value * 360 / maximumValue; }
#endregion } } |
▶ MainForm.cs
using System; using System.Drawing; using System.Windows.Forms;
namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent();
this.leftCircularProgressBar.ForegroundPenColor = Color.BlueViolet;
this.timer.Tick += timer_Tick;
this.timer.Start(); }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private
#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.leftCircularProgressBar.Value >= 100) { this.leftCircularProgressBar.Value = 0; }
if(this.rightCircularProgressBar.Value >= 100) { this.rightCircularProgressBar.Value = 0; }
this.leftCircularProgressBar.Value += 1; this.rightCircularProgressBar.Value += 3; }
#endregion } }
|
------------------------------------------------------------------------------------------------------------------------
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Bitmap 클래스 : 비트맵 회전하기 (0) | 2019.12.23 |
---|---|
[C#/WINFORM] Form 클래스 : 마우스 위치에 따라 폼 불투명도 변경하기 (0) | 2019.11.29 |
[C#/WINFORM] TreeView 클래스 : 드래그 & 드롭 사용하기 (0) | 2019.10.03 |
[C#/WINFORM] TreeView 클래스 : 첫번째 종말 노드 구하기 (0) | 2019.09.15 |
[C#/WINFORM] TreeView 클래스 : 특정 레벨까지 노드 확장하기 (0) | 2019.09.15 |
[C#/WINFORM] UserControl 클래스 : 환형 진행바 사용하기 (0) | 2019.08.31 |
[C#/WINFORM] Bitmap 클래스 : 투명 배경 비트맵 구하기 (0) | 2019.08.30 |
[C#/WINFORM] Form 클래스 : KeyPreview 속성을 사용해 단축키 설정하기 (0) | 2019.08.30 |
[C#/WINFORM] DesignerSerializationVisibilityAttribute 클래스 : 디자이너 모드에서 속성 코드 자동 생성 막기 (0) | 2019.08.26 |
[C#/WINFORM] 가상 리스트 박스 사용하기 (0) | 2019.08.16 |
[C#/WINFORM] Process 클래스 : GetProcessesByName 정적 메소드를 사용해 프로그램 중복 실행 여부 구하기 (0) | 2019.08.16 |
댓글을 달아 주세요