728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 무어의 이웃 등고선 추적 (Moore Neighbor Contour Tracing) 알고리즘 사용하기 (0) | 2018.04.12 |
---|---|
[C#/WINFORM] DirectShow를 사용해 동영상 재생하기 (0) | 2018.04.02 |
[C#/WINFORM] 설치 프린터 조회하기 (0) | 2018.03.22 |
[C#/WINFORM] 윈폼(WinForm)에서 콘솔(Console) 사용하기 (0) | 2018.03.22 |
[C#/WINFORM] BitBlt 함수를 사용해 비트맵 복사하기 (0) | 2018.03.15 |
[C#/WINFORM] PropertyGrid 클래스 : 목록을 사용해 항목 값 선택하기 (0) | 2018.03.04 |
[C#/WINFORM] PropertyGrid 클래스 사용하기 (0) | 2018.03.04 |
[C#/WINFORM] GroupBox 클래스 : 테두리 색상 설정하기 (0) | 2018.03.04 |
[C#/WINFORM] Form 클래스 : 폼 닫히는 것을 방지하기 (0) | 2018.03.04 |
[C#/WINFORM] 크로스 스레드(Cross Thread) 처리하기 (0) | 2018.03.04 |
댓글을 달아 주세요