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

TestProject.zip
다운로드

▶ MainWindow.cs

using System;
using System.Windows;
using System.Windows.Media;

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

        #region Field

        /// <summary>
        /// 브러시
        /// </summary>
        private LinearGradientBrush brush;

        #endregion

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

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            Title = "LinearGradientBrush 클래스 : MappingMode 속성 사용하기";

            Width  = 800;
            Height = 600;

            SizeChanged += Window_SizeChanged;

            this.brush = new LinearGradientBrush(Colors.Red, Colors.Blue, 0);

            this.brush.MappingMode = BrushMappingMode.Absolute;

            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
        //////////////////////////////////////////////////////////////////////////////// Private

        #region 윈도우 크기 변경시 처리하기 - Window_SizeChanged(sender, e)

        /// <summary>
        /// 윈도우 크기 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double clientAreaWidth  = ActualWidth  - 2 * SystemParameters.ResizeFrameVerticalBorderWidth;
            double clientAreaHeight = ActualHeight - 2 * SystemParameters.ResizeFrameHorizontalBorderHeight - SystemParameters.CaptionHeight;

            Point  clientAreaCenterPoint = new Point(clientAreaWidth / 2, clientAreaHeight / 2);
            Vector diagonalVector        = new Vector(clientAreaWidth, -clientAreaHeight);
            Vector perpendicularVector   = new Vector(diagonalVector.Y, -diagonalVector.X);

            perpendicularVector.Normalize();

            perpendicularVector *= clientAreaWidth * clientAreaHeight / diagonalVector.Length;

            this.brush.StartPoint = clientAreaCenterPoint + perpendicularVector;
            this.brush.EndPoint   = clientAreaCenterPoint - perpendicularVector;
        }

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

댓글을 달아 주세요