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

TestProject.zip
다운로드

▶ MainForm.cs

using System;
using System.Drawing;
using System.Windows.Forms;

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

        #region Field

        /// <summary>
        /// 버튼에서 강아지 표시 여부
        /// </summary>
        private bool isShowPuppyInButton = false;

        /// <summary>
        /// 픽처 박스에서 강아지 표시 여부
        /// </summary>
        private bool isShowPuppyInPictureBox = false;

        /// <summary>
        /// 레이블에서 외계인 표시 여부
        /// </summary>
        private bool isShowAlienInLabel = false;

        /// <summary>
        /// 외계인 이미지
        /// </summary>
        private Image alienImage = null;

        /// <summary>
        /// 강아지 이미지
        /// </summary>
        private Image puppuImage = null;

        /// <summary>
        /// 공사중 이미지
        /// </summary>
        private Image underConstructionImage = null;

        #endregion

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

        #region 생성자 - MainForm()

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

            this.alienImage             = Image.FromFile("Image\\alien.gif"             );
            this.puppuImage             = Image.FromFile("Image\\puppy.gif"             );
            this.underConstructionImage = Image.FromFile("Image\\under_construction.gif");

            this.button.Image     = this.underConstructionImage;
            this.pictureBox.Image = this.underConstructionImage;
            this.label.Image      = this.underConstructionImage;

            #region 이벤트를 설정한다.

            this.button.Click     += button_Click;
            this.pictureBox.Click += pictueBox_Click;
            this.label.Click      += label_Click;

            #endregion
        }

        #endregion

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

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

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

            if(this.isShowPuppyInButton)
            {
                this.button.Image = this.puppuImage;
            }
            else
            {
                this.button.Image = this.underConstructionImage;
            }
        }

        #endregion
        #region 픽처 박스 클릭시 처리하기 - pictueBox_Click(sender, e)

        /// <summary>
        /// 픽처 박스 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void pictueBox_Click(object sender, EventArgs e)
        {
            this.isShowPuppyInPictureBox = !this.isShowPuppyInPictureBox;

            if(this.isShowPuppyInPictureBox)
            {
                this.pictureBox.Image = this.puppuImage;
            }
            else
            {
                this.pictureBox.Image = this.underConstructionImage;
            }
        }

        #endregion
        #region 레이블 클릭시 처리하기 - label_Click(sender, e)

        /// <summary>
        /// 레이블 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void label_Click(object sender, EventArgs e)
        {
            this.isShowAlienInLabel = !this.isShowAlienInLabel;

            if(this.isShowAlienInLabel)
            {
                this.label.Image = this.alienImage;
            }
            else
            {
                this.label.Image = this.underConstructionImage;
            }
        }

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

댓글을 달아 주세요