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

■ GroupBox 클래스에서 체크 그룹 박스를 사용하는 방법을 보여준다.

TestProject.zip
다운로드

▶ MainForm.cs

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();

            #region 이벤트를 설정한다.

            this.breakfastCheckBox.CheckedChanged += breakfastCheckBox_CheckedChanged;
            this.lunchCheckBox.CheckedChanged     += lunchCheckBox_CheckedChanged;

            #endregion
        }

        #endregion

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

        #region 아침 체크 박스 체크 변경시 처리하기 - breakfastCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 아침 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void breakfastCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            SetCheckGroupBox(this.breakfastCheckBox, this.breakfastGroupBox);
        }

        #endregion
        #region 점심 체크 박스 체크 변경시 처리하기 - lunchCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 점심 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void lunchCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            SetCheckGroupBox(this.lunchCheckBox, this.lunchGroupBox);
        }

        #endregion

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

        #region 체크 그룹 박스 설정하기 - SetCheckGroupBox(checkBox, groupBox)

        /// <summary>
        /// 체크 그룹 박스 설정하기
        /// </summary>
        /// <param name="checkBox">체크 박스</param>
        /// <param name="groupBox">그룹 박스</param>
        private void SetCheckGroupBox(CheckBox checkBox, GroupBox groupBox)
        {
            if(checkBox.Parent == groupBox)
            {
                groupBox.Parent.Controls.Add(checkBox);

                checkBox.Location = new Point
                (
                    checkBox.Left + groupBox.Left,
                    checkBox.Top  + groupBox.Top
                );

                checkBox.BringToFront();
            }

            groupBox.Enabled = checkBox.Checked;
        }

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

댓글을 달아 주세요