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

TestProject.zip
0.01MB

▶ MainForm.cs

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>
        /// 그래픽스 경로 1
        /// </summary>
        private GraphicsPath graphicsPath1;

        /// <summary>
        /// 그래픽스 경로 2
        /// </summary>
        private GraphicsPath graphicsPath2;

        /// <summary>
        /// 영역 2
        /// </summary>
        private Region region2;

        /// <summary>
        /// 사각형 3
        /// </summary>
        private Rectangle rectangle3;

        /// <summary>
        /// 그래픽스 경로 1 내부 위치 여부
        /// </summary>
        private bool inGraphicsPath1 = false;

        /// <summary>
        /// 영역 2 내부 위치 여부
        /// </summary>
        private bool inRegion2 = false;

        /// <summary>
        /// 사각형 3 내부 위치 여부
        /// </summary>
        private bool inRectangle3 = false;

        #endregion

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

        #region 생성자 - MainForm()

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

            this.graphicsPath1 = new GraphicsPath();

            this.graphicsPath1.AddLine(50 , 50 , 170, 50 );
            this.graphicsPath1.AddLine(170, 50 , 170, 140);
            this.graphicsPath1.AddLine(170, 140, 50 , 170);

            this.graphicsPath1.CloseFigure();

            this.graphicsPath2 = new GraphicsPath();

            this.graphicsPath2.AddLine(200, 50 , 380, 50 );
            this.graphicsPath2.AddLine(380, 50 , 380, 140);
            this.graphicsPath2.AddLine(380, 140, 470, 140);
            this.graphicsPath2.AddLine(470, 140, 470, 200);
            this.graphicsPath2.AddLine(470, 200, 320, 200);
            this.graphicsPath2.AddLine(320, 200, 320, 140);
            this.graphicsPath2.AddLine(320, 140, 200, 140);

            this.graphicsPath2.CloseFigure();

            this.region2 = new Region(graphicsPath2);

            this.rectangle3 = new Rectangle(50, 290, 260, 200);

            MouseMove += Form_MouseMove;
            Paint     += Form_Paint;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼 마우스 이동시 처리하기 - Form_MouseMove(sender, e)

        /// <summary>
        /// 폼 마우스 이동시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_MouseMove(object sender, MouseEventArgs e)
        {
            Graphics graphics = CreateGraphics();

            try
            {
                if(this.inGraphicsPath1)
                {
                    if(!this.graphicsPath1.IsVisible(e.X, e.Y))
                    {
                        graphics.FillPath(Brushes.White, this.graphicsPath1);

                        graphics.DrawPath(Pens.Black, this.graphicsPath1);

                        this.inGraphicsPath1 = false;

                        return;
                    }
                }
                else
                {
                    if(this.graphicsPath1.IsVisible(e.X, e.Y))
                    {
                        graphics.FillPath(Brushes.LightBlue, this.graphicsPath1);

                        graphics.DrawPath(Pens.Black, this.graphicsPath1);

                        this.inGraphicsPath1 = true;

                        return;
                    }
                }

                if(this.inRegion2)
                {
                    if(!this.region2.IsVisible(e.X, e.Y))
                    {
                        graphics.FillRegion(Brushes.White, this.region2);

                        graphics.DrawPath(Pens.Black, this.graphicsPath2);

                        this.inRegion2 = false;

                        return;
                    }
                }
                else
                {
                    if(this.region2.IsVisible(e.X, e.Y))
                    {
                        graphics.FillRegion(Brushes.Pink, this.region2);

                        graphics.DrawPath(Pens.Black, this.graphicsPath2);

                        this.inRegion2 = true;

                        return;
                    }
                }

                if(this.inRectangle3)
                {
                    if(!this.rectangle3.Contains(e.X, e.Y))
                    {
                        graphics.FillRectangle(Brushes.White, this.rectangle3);

                        graphics.DrawRectangle(Pens.Black, this.rectangle3);

                        this.inRectangle3 = false;

                        return;
                    }
                }
                else
                {
                    if(this.rectangle3.Contains(e.X, e.Y))
                    {
                        graphics.FillRectangle(Brushes.LightGreen, this.rectangle3);

                        graphics.DrawRectangle(Pens.Black, this.rectangle3);

                        this.inRectangle3 = true;

                        return;
                    }
                }
            }            
            finally
            {
                graphics.Dispose();
            }
        }

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

        /// <summary>
        /// 폼 페인트시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphics = e.Graphics;

            graphics.FillRectangle(Brushes.White, ClientRectangle);

            graphics.DrawPath(Pens.Black, graphicsPath1);

            graphics.DrawPath(Pens.Black, graphicsPath2);

            graphics.DrawRectangle(Pens.Black, rectangle3);
        }

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