728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] RichTextBox 클래스 사용하기 (0) | 2018.03.18 |
---|---|
[C#/WPF] ToggleButton 클래스 사용하기 (0) | 2018.03.10 |
[C#/WPF] CommandBinding 클래스 사용하기 (0) | 2018.03.10 |
[C#/WPF] FrameworkElement 클래스 : 커스텀 엘리먼트 사용하기 (0) | 2018.03.10 |
[C#/WPF] RadialGradientBrush 클래스 사용하기 (0) | 2018.03.10 |
[C#/WPF] Type 클래스 : GetProperties 메소드 사용하기 (0) | 2018.03.10 |
[C#/WPF] Window 클래스 : Background 속성을 사용해 배경색 변경하기 (0) | 2018.03.10 |
[C#/WPF] Application, Window 클래스 상속하기 (0) | 2018.03.10 |
[C#/WPF] XAML에서 특수 문자 사용하기 (0) | 2018.03.04 |
[C#/WPF] MediaElement 클래스 사용하기 (0) | 2018.02.18 |
댓글을 달아 주세요