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

TestProject.zip
다운로드

▶ MainWindow.cs

using System;
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 SolidColorBrush brush = new SolidColorBrush(Colors.Black);

        #endregion

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

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            Title      = "배경색 변경하기";
            Width      = 800;
            Height     = 600;
            Background = this.brush;
        }

        #endregion

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

        #region 프로그램 시작하기 - Main()

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

            application.Run(new MainWindow());
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Protected

        #region 마우스 이동시 처리하기 - OnMouseMove(e)

        /// <summary>
        /// 마우스 이동시 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            double clientAreaWidth  = ActualWidth  - 2 * SystemParameters.ResizeFrameVerticalBorderWidth;
            double clientAreaHeight = ActualHeight - 2 * SystemParameters.ResizeFrameHorizontalBorderHeight - SystemParameters.CaptionHeight;

            Point  clientAreaCenterPoint = new Point(clientAreaWidth / 2, clientAreaHeight / 2);
            Point  mousePoint            = e.GetPosition(this);
            Vector mouseVector           = mousePoint - clientAreaCenterPoint;
            double mouseRadianAngle      = Math.Atan2(mouseVector.Y, mouseVector.X);
            Vector ellipseVector         = new Vector(clientAreaWidth / 2 * Math.Cos(mouseRadianAngle), clientAreaHeight / 2 * Math.Sin(mouseRadianAngle));
            Byte   backgroundColorLevel  = (byte) (255 * (1 - Math.Min(1, mouseVector.Length / ellipseVector.Length)));
            Color  backgroundColor       = this.brush.Color;

            backgroundColor.R = backgroundColor.G = backgroundColor.B = backgroundColorLevel;

            this.brush.Color = backgroundColor;
        }

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

댓글을 달아 주세요