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

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Windows.Forms;

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

        #region Field

        /// <summary>
        /// 도형 버튼 배열
        /// </summary>
        private ToolStripButton[] shapeButtonArray;
        
        /// <summary>
        /// 색상 버튼 배열
        /// </summary>
        private ToolStripButton[] colorButtonArray;

        #endregion

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

        #region 생성자 - MainForm()

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

            #region 이벤트를 설정한다.

            Load                     += Form_Load;
            this.selectButton.Click  += button_Click;
            this.polygonButton.Click += button_Click;
            this.circleButton.Click  += button_Click;
            this.diamondButton.Click += button_Click;
            this.redButton.Click     += button_Click;
            this.blueButton.Click    += button_Click;
            this.yellowButton.Click  += button_Click;
            this.limeButton.Click    += button_Click;

            #endregion
        }

        #endregion

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

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            this.shapeButtonArray = new ToolStripButton[]
            {
                this.selectButton,
                this.polygonButton,
                this.circleButton,
                this.diamondButton
            };

            foreach(ToolStripButton button in shapeButtonArray)
            {
                button.Click += shapeButton_Click;
            }

            this.colorButtonArray = new ToolStripButton[]
            {
                this.redButton,
                this.blueButton,
                this.yellowButton,
                this.limeButton
            };

            foreach(ToolStripButton button in colorButtonArray)
            {
                button.Click += colorButton_Click;
            }
        }

        #endregion
        #region 버튼 클릭시 처리하기 - button_Click(sender, e)

        /// <summary>
        /// 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void button_Click(object sender, EventArgs e)
        {
            ToolStripButton button = sender as ToolStripButton;

            MessageBox.Show(this, button.Text);
        }

        #endregion
        #region 도형 버튼 클릭시 처리하기 - shapeButton_Click(sender, e)

        /// <summary>
        /// 도형 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void shapeButton_Click(object sender, EventArgs e)
        {
            SelectButton(sender as ToolStripButton, shapeButtonArray);
        }

        #endregion
        #region 색상 버튼 클릭시 처리하기- colorButton_Click(sender, e)

        /// <summary>
        /// 색상 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void colorButton_Click(object sender, EventArgs e)
        {
            SelectButton(sender as ToolStripButton, colorButtonArray);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 버튼 선택하기 - SelectButton(selectButton, buttonArray)

        /// <summary>
        /// 버튼 선택하기
        /// </summary>
        /// <param name="selectButton">선택 버튼</param>
        /// <param name="buttonArray">버튼 배열</param>
        private void SelectButton(ToolStripButton selectButton, ToolStripButton[] buttonArray)
        {
            foreach(ToolStripButton button in buttonArray)
            {
                button.Checked = (button == selectButton);
            }
        }

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

댓글을 달아 주세요