Mega Code Archive

 
Categories / C# Tutorial / WPF
 

Using SolidColorBrush to paint the window background

using System; using System.Windows; using System.Windows.Input; using System.Windows.Media;     public class MainClass : Window     {         SolidColorBrush brush = new SolidColorBrush(Colors.Black);         [STAThread]         public static void Main()         {             Application app = new Application();             app.Run(new MainClass());         }         public MainClass()         {             Width = 400;             Height = 400;             Background = brush;         }         protected override void OnMouseMove(MouseEventArgs args)         {             double width = 330;             double height = 350;             Point ptMouse = args.GetPosition(this);             Point ptCenter = new Point(width / 2, height / 2);             Vector vectMouse = ptMouse - ptCenter;             double angle = Math.Atan2(vectMouse.Y, vectMouse.X);             Vector vectEllipse = new Vector(width / 2 * Math.Cos(angle),height / 2 * Math.Sin(angle));             Byte byLevel = 123;             Color clr = brush.Color;             clr.R = clr.G = clr.B = byLevel;             brush.Color = clr;         }     }