첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

TestProject.zip
다운로드

▶ 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
반응형
Posted by 사용자 icodebroker

댓글을 달아 주세요