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

TestProject.zip
다운로드

▶ MainWindow.cs

using System;
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 속성 정보 배열
        /// </summary>
        private PropertyInfo[] propertyInfoArray;

        /// <summary>
        /// 속성 정보 배열 인덱스
        /// </summary>
        private int propertyInfoArrayIndex = 0;

        #endregion

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

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            this.propertyInfoArray = typeof(Brushes).GetProperties(BindingFlags.Public | BindingFlags.Static);

            Width  = 800;
            Height = 600;

            SetTitleAndBackground();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 프로그램 실행하기 - Main()

        /// <summary>
        /// 프로그램 실행하기
        /// </summary>
        [STAThread]
        public static void Main()
        {
            Application application = new Application();

            application.Run(new MainWindow());
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 키 다운시 처리하기 - OnKeyDown(e)

        /// <summary>
        /// 키 다운시 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if(e.Key == Key.Down || e.Key == Key.Up)
            {
                this.propertyInfoArrayIndex += e.Key == Key.Up ? 1 : this.propertyInfoArray.Length - 1;
                this.propertyInfoArrayIndex %= this.propertyInfoArray.Length;

                SetTitleAndBackground();
            }

            base.OnKeyDown(e);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Private

        #region 제목/배경 설정하기 - SetTitleAndBackground()

        /// <summary>
        /// 제목/배경 설정하기
        /// </summary>
        private void SetTitleAndBackground()
        {
            Title = "Type 클래스 : GetProperties 메소드 사용하기 : " + this.propertyInfoArray[this.propertyInfoArrayIndex].Name;

            Background = this.propertyInfoArray[this.propertyInfoArrayIndex].GetValue(null, null) as Brush;
        }

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

댓글을 달아 주세요