using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SayHello
{
//可以修改的LinearGradientBrush对象
public class GradiateTheBrush:Window
{
private LinearGradientBrush brush;
[STAThread]
public static void Main()
{
Application app=new Application();
//5.运行当前Window
app.Run(new GradiateTheBrush());
}
public GradiateTheBrush()
{
Title = "Gradiate the Brush";
SizeChanged += WinowOnSizeChanged;
brush = new LinearGradientBrush(Colors.Red, Colors.Blue, 0);
brush.MappingMode = BrushMappingMode.Absolute;
Background = brush;
}
void WinowOnSizeChanged(object sender,SizeChangedEventArgs args)
{
double width = ActualWidth - 2*SystemParameters.ResizeFrameVerticalBorderWidth;
double height = ActualHeight - 2*SystemParameters.ResizeFrameHorizontalBorderHeight;
Point ptCender = new Point(width/2, height/2);
Vector vecDiag = new Vector(width, -height);
Vector vectdiap = new Vector(vecDiag.Y, vecDiag.X);
vectdiap.Normalize();
vectdiap *= width*height/vecDiag.Length;
brush.StartPoint = ptCender + vectdiap;
brush.EndPoint = ptCender - vectdiap;
}
}
}
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace SayHello
{
//可以修改的LinearGradientBrush对象
public class GradiateTheBrush:Window
{
private LinearGradientBrush brush;
[STAThread]
public static void Main()
{
Application app=new Application();
//5.运行当前Window
app.Run(new GradiateTheBrush());
}
public GradiateTheBrush()
{
Title = "Gradiate the Brush";
SizeChanged += WinowOnSizeChanged;
brush = new LinearGradientBrush(Colors.Red, Colors.Blue, 0);
brush.MappingMode = BrushMappingMode.Absolute;
Background = brush;
}
void WinowOnSizeChanged(object sender,SizeChangedEventArgs args)
{
double width = ActualWidth - 2*SystemParameters.ResizeFrameVerticalBorderWidth;
double height = ActualHeight - 2*SystemParameters.ResizeFrameHorizontalBorderHeight;
Point ptCender = new Point(width/2, height/2);
Vector vecDiag = new Vector(width, -height);
Vector vectdiap = new Vector(vecDiag.Y, vecDiag.X);
vectdiap.Normalize();
vectdiap *= width*height/vecDiag.Length;
brush.StartPoint = ptCender + vectdiap;
brush.EndPoint = ptCender - vectdiap;
}
}
}