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

TestProject.zip
다운로드

▶ Direction.cs

namespace TestProject
{
    /// <summary>
    /// 방향
    /// /// </summary>
    public enum Direction : int
    {
        /// <summary>
        /// LEFT
        /// </summary>
        LEFT,

        /// <summary>
        /// UP
        /// </summary>
        UP,

        /// <summary>
        /// RIGHT
        /// </summary>
        RIGHT,

        /// <summary>
        /// DOWN
        /// </summary>
        DOWN
    }
}

 

728x90

 

▶ Car.cs

using System.ComponentModel;
using System.Drawing.Design;

namespace TestProject
{
    /// <summary>
    /// 자동차
    /// </summary>
    public class Car
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 방향 - Direction

        /// <summary>
        /// 방향
        /// </summary>
        [Category("Car")]
        [Description("자동차 방향")]
        [Editor(typeof(DirectionEditor), typeof(UITypeEditor))]
        public Direction Dicrection { get; set; }

        #endregion

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

        #region 생성자 - Car

        /// <summary>
        /// 생성자
        /// </summary>
        public Car()
        {
        }

        #endregion
    }
}

 

300x250

 

▶ DirectionEditor.cs

using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;

namespace TestProject
{
    /// <summary>
    /// 방향 에디터
    /// </summary>
    public class DirectionEditor : UITypeEditor
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 페인트 값 지원 여부 구하기 - GetPaintValueSupported(context)

        /// <summary>
        /// 페인트 값 지원 여부 구하기
        /// </summary>
        /// <param name="context">컨텍스트</param>
        /// <returns>페인트 값 지원 여부</returns>
        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        #endregion
        #region 값 페인트 하기 - PaintValue(e)

        /// <summary>
        /// 값 페인트 하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        public override void PaintValue(PaintValueEventArgs e)
        {
            Direction value = (Direction)e.Value;
 
            Image image = null;

            switch(value)
            {
                case Direction.LEFT  : image = Properties.Resources.left;  break;
                case Direction.UP    : image = Properties.Resources.up;    break;
                case Direction.RIGHT : image = Properties.Resources.right; break;
                case Direction.DOWN  : image = Properties.Resources.down;  break;
            }
 
            int x = (e.Bounds.Width - image.Width) / 2 + e.Bounds.X;
            int y = e.Bounds.Y;

            e.Graphics.DrawImage(image, x, y);
        }

        #endregion
    }
}

 

▶ MainForm.cs

using System;
using System.Windows.Forms;

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

        #region 생성자 - MainForm()

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

            this.setButton.Click += setButton_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 설정 버튼 클릭시 처리하기 - setButton_Click(sender, e)

        /// <summary>
        /// 설정 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void setButton_Click(object sender, EventArgs e)
        {
            Car car = new Car();

            car.Dicrection = Direction.DOWN;

            propertyGrid.SelectedObject = car;
        }

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

댓글을 달아 주세요