728x90
반응형
728x170
▶ MainForm.cs
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 이벤트를 설정한다.
Paint += Form_Paint;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 페인트시 처리하기 - Form_Paint(sender, e)
/// <summary>
/// 폼 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Paint(object sender, PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
int size = (ClientSize.Width > ClientSize.Height ? ClientSize.Height : ClientSize.Width) - 20;
int left = (ClientSize.Width - size) / 2;
int top = (ClientSize.Height - size) / 2;
DrawColorWheel(e.Graphics, BackColor, left, top, size, size);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 색상 휠 그리기 - DrawColorWheel(graphics, outlineColor, minimumX, minimumY, width, height)
/// <summary>
/// 색상 휠 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="outlineColor">외곽선 색상</param>
/// <param name="minimumX">최소 X 좌표</param>
/// <param name="minimumY">최소 Y 좌표</param>
/// <param name="width">너비</param>
/// <param name="height">높이</param>
private void DrawColorWheel(Graphics graphics, Color outlineColor, int minimumX, int minimumY, int width, int height)
{
Rectangle rectangle = new Rectangle(minimumX, minimumY, width, height);
GraphicsPath wheelGraphicsPath = new GraphicsPath();
wheelGraphicsPath.AddEllipse(rectangle);
wheelGraphicsPath.Flatten();
int pointCount = (wheelGraphicsPath.PointCount - 1) / 3;
Color[] surroundColorArray = new Color[wheelGraphicsPath.PointCount];
float red = 255;
float green = 0;
float blue = 0;
float deltaRed;
float deltaGreen;
float deltaBlue;
deltaRed = -255 / pointCount;
deltaBlue = 255 / pointCount;
for(int i= 0; i < pointCount; i++)
{
surroundColorArray[i] = Color.FromArgb(255, (int)red, (int)green, (int)blue);
red += deltaRed;
blue += deltaBlue;
}
red = 0;
green = 0;
blue = 255;
deltaGreen = 255 / pointCount;
deltaBlue = -255 / pointCount;
for(int i = pointCount; i < 2 * pointCount; i++)
{
surroundColorArray[i] = Color.FromArgb(255, (int)red, (int)green, (int)blue);
green += deltaGreen;
blue += deltaBlue;
}
red = 0;
green = 255;
blue = 0;
deltaRed = 255 / (wheelGraphicsPath.PointCount - 2 * pointCount);
deltaGreen = -255 / (wheelGraphicsPath.PointCount - 2 * pointCount);
for(int i = 2 * pointCount; i < wheelGraphicsPath.PointCount; i++)
{
surroundColorArray[i] = Color.FromArgb(255, (int)red, (int)green, (int)blue);
red += deltaRed;
green += deltaGreen;
}
using(PathGradientBrush pathBrush = new PathGradientBrush(wheelGraphicsPath))
{
pathBrush.CenterColor = Color.White;
pathBrush.SurroundColors = surroundColorArray;
graphics.FillPath(pathBrush, wheelGraphicsPath);
using(Pen thickPen = new Pen(outlineColor, 2))
{
graphics.DrawPath(thickPen, wheelGraphicsPath);
}
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 마우스 아래 파이 슬라이스 구하기 (0) | 2018.12.30 |
---|---|
[C#/WINFORM] 프린터 해상도 설정하기 (0) | 2018.12.30 |
[C#/WINFORM] 색상 휠 대화 상자 사용하기 (0) | 2018.12.30 |
[C#/WINFORM] 투명도와 채도를 적용한 색상 휠 사용하기 (0) | 2018.12.30 |
[C#/WINFORM] 색상 휠 그리기 (0) | 2018.12.30 |
[C#/WINFORM] 시스템 아이콘 사용하기 (0) | 2018.12.30 |
[C#/WINFORM] 정규 분포 곡선(Normal Distribution Curve) 그리기 (0) | 2018.12.30 |
[C#/WINFORM] 정규 분포 곡선(Normal Distribution Curve) 그리기 (0) | 2018.12.29 |
[C#/WINFORM] 재귀적으로 하노이 탑 문제 풀기 (0) | 2018.12.29 |
[C#/WINFORM] 움직이는 기어 사용하기 (0) | 2018.12.29 |
댓글을 달아 주세요