■ PropertyGrid 클래스에서 목록을 사용해 항목 값을 선택하는 방법을 보여준다.
▶ Customer.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
using System; using System.ComponentModel; using System.Drawing; namespace TestProject { /// <summary> /// 고객 /// </summary> public class Customer { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 성명 - Name /// <summary> /// 성명 /// </summary> [Category("ID 설정")] [Description("고객명")] public string Name { get; set; } #endregion #region 나이 - Age /// <summary> /// 나이 /// </summary> [Category("ID 설정")] [Description("나이")] public int Age { get; set; } #endregion #region 생일 - Birthday /// <summary> /// 생일 /// </summary> [Category("ID 설정")] [Description("생일")] public DateTime Birthday { get; set; } #endregion #region 주민등록번호 - SSN /// <summary> /// 주민등록번호 /// </summary> [Category("ID 설정")] [Description("주민등록번호")] public string SSN { get; set; } #endregion #region 주소 - Address /// <summary> /// 주소 /// </summary> [Category("ID 설정")] [Description("주소")] [TypeConverter(typeof(AddressConverter))] public string Address { get; set; } #endregion #region E 메일 주소 - EMailAddress /// <summary> /// E 메일 주소 /// </summary> [Category("마케팅 설정")] [Description("E 메일 주소")] public string EMailAddress { get; set; } #endregion #region 단골 고객 여부 - IsFrequentBuyer /// <summary> /// 단골 고객 여부 /// </summary> [Category("마케팅 설정")] [Description("단골 고객 여부")] public bool IsFrequentBuyer { get; set; } #endregion #region 테스트 색상 - TestColor /// <summary> /// 테스트 색상 /// </summary> [Category("ID 설정")] [Description("테스트 색상")] public Color TestColor { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - Customer /// <summary> /// 생성자 /// </summary> public Customer() { } #endregion } } |
▶ AddressConverter.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
using System.ComponentModel; namespace TestProject { /// <summary> /// 주소 변환자 /// </summary> public class AddressConverter : StringConverter { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 주소 배열 /// </summary> private string[] addressArray = new string[] { "서울시 강남구", "서울시 관악구", "서울시 중구" }; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 표준 값 지원 여부 구하기 - GetStandardValuesSupported(context) /// <summary> /// 표준 값 지원 여부 구하기 /// </summary> /// <param name="context">컨텍스트</param> /// <returns>표준 값 지원 여부</returns> public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } #endregion #region 표준 값 단독 여부 구하기 - GetStandardValuesExclusive(context) /// <summary> /// 표준 값 단독 여부 구하기 /// </summary> /// <param name="context">컨텍스트</param> /// <returns>표준 값 단독 여부</returns> public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } #endregion #region 표준 값 구하기 - GetStandardValues(context) /// <summary> /// 표준 값 구하기 /// </summary> /// <param name="context">컨텍스트</param> /// <returns>표준 값</returns> public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection(this.addressArray); } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
using System; using System.Drawing; 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) { Customer customer = new Customer(); customer.Name = "홍길동"; customer.Age = 18; customer.Birthday = new DateTime(2000, 1, 1); customer.SSN = "000101-3234567"; customer.Address = "서울시 관악구"; customer.EMailAddress = "test@daum.com"; customer.TestColor = Color.Red; propertyGrid.SelectedObject = customer; } #endregion } } |