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

TestProject.zip
다운로드

▶ MainForm.cs

using System;
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();

            ResizeRedraw = true;

            #region 이벤트를 설정한다.

            this.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)
        {
            int      sideCount  = 8;
            PointF[] pointArray = new PointF[sideCount];

            int centerX = (int)(ClientSize.Width  / 2);
            int centerY = (int)(ClientSize.Height / 2);

            double theta  = 0;
            double dtheta = 2 * Math.PI / sideCount;

            for(int i = 0; i < pointArray.Length; i++)
            {
                pointArray[i].X = (int)(centerX + centerX * Math.Cos(theta));
                pointArray[i].Y = (int)(centerY + centerY * Math.Sin(theta));

                theta += dtheta;
            }

            using(PathGradientBrush brush = new PathGradientBrush(pointArray))
            {
                brush.CenterColor = Color.White;

                brush.SurroundColors = new Color[]
                {
                    Color.Red,
                    Color.Yellow,
                    Color.Lime,
                    Color.Cyan,
                    Color.Blue,
                    Color.Magenta
                };
                    
                e.Graphics.FillPolygon(brush, pointArray);
            }

            e.Graphics.DrawPolygon(Pens.Black, pointArray);
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요