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

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 마진
        /// </summary>
        private const int MARGIN = 10;

        /// <summary>
        /// 중심 X
        /// </summary>
        private int centerX;
        
        /// <summary>
        /// 중심 Y
        /// </summary>
        private int centerY;
        
        /// <summary>
        /// 너비
        /// </summary>
        private int width;
        
        /// <summary>
        /// 높이
        /// </summary>
        private int height;

        /// <summary>
        /// 포인트 리스트
        /// </summary>
        private List<PointF> pointList = null;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            ResizeRedraw = true;

            #region 이벤트를 설정한다.

            Load   += Form_Load;
            Resize += Form_Resize;
            Paint  += Form_Paint;

            #endregion
        }

        #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)
        {
            SetDrawingObject();
        }

        #endregion
        #region 폼 크기 조정시 처리하기 - Form_Resize(sender, e)

        /// <summary>
        /// 폼 크기 조정시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Resize(object sender, EventArgs e)
        {
            SetDrawingObject();
        }

        #endregion
        #region 폼 페인트시 처리하기 - Form_Paint(sender, e)

        /// <summary>
        /// 폼 페인트시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Paint(object sender, PaintEventArgs e)
        {
            if((this.width <= 0) || (this.height <= 0))
            {
                return;
            }

            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

            e.Graphics.FillEllipse(Brushes.LightBlue, MARGIN, MARGIN, this.width, this.height);

            e.Graphics.DrawEllipse(Pens.Blue, MARGIN, MARGIN, this.width, this.height);

            e.Graphics.DrawLines(Pens.Blue, this.pointList.ToArray());
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 그리기 객체 설정하기 - SetDrawingObject()

        /// <summary>
        /// 그리기 객체 설정하기
        /// </summary>
        private void SetDrawingObject()
        {
            this.width  = ClientSize.Width  - 2 * MARGIN;
            this.height = ClientSize.Height - 2 * MARGIN;

            this.centerX = ClientSize.Width  / 2;
            this.centerY = ClientSize.Height / 2;

            Random random = new Random();

            double circumference = 2 * Math.PI * Math.Sqrt((this.width * this.width + this.height * this.height) / 2);

            int pointCount = (int)(circumference / 40);

            this.pointList = new List<PointF>();

            for(int i = 0; i < pointCount; i++)
            {
                double theta1 = 2 * Math.PI * random.NextDouble();

                float x1 = (float)(this.centerX + Math.Cos(theta1) * this.width  / 2);
                float y1 = (float)(this.centerY + Math.Sin(theta1) * this.height / 2);

                this.pointList.Add(new PointF(x1, y1));

                double theta2 = 2 * Math.PI * random.NextDouble();

                float x2 = (float)(this.centerX + Math.Cos(theta2) * this.width  / 2);
                float y2 = (float)(this.centerY + Math.Sin(theta2) * this.height / 2);

                this.pointList.Add(new PointF(x2, y2));
            }
        }

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

댓글을 달아 주세요