Window1.xaml.cs
上传用户:haomiao527
上传日期:2008-10-28
资源大小:322k
文件大小:9k
源码类别:

其他智力游戏

开发平台:

C#

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. namespace CShap.Wpf.EinsteinSuperQuestion
  15. {
  16.     /// <summary>
  17.     /// Window1.xaml 的交互逻辑
  18.     /// </summary>
  19.     public partial class Window1 : Window
  20.     {
  21.         Point ptEllipseMove, ptEllipsePositon, ptModifier;
  22.         public Window1()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.         protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
  27.         {
  28.             base.OnMouseLeftButtonDown(e);
  29.             if (grdCaption.Equals(e.Source as Grid))
  30.             {
  31.                 this.DragMove();
  32.             }
  33.         }
  34.         private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
  35.         {
  36.             LinearGradientBrush brush = new LinearGradientBrush(Colors.White, Colors.Yellow, new Point(0.5, 0), new Point(0.5, 0.5));
  37.             (sender as TextBlock).Foreground = brush;
  38.         }
  39.         private void TextBlock_MouseLeave(object sender, MouseEventArgs e)
  40.         {
  41.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.GreenYellow, new Point(0.5, 0), new Point(0.5, 0.3));
  42.             (sender as TextBlock).Foreground = brush;
  43.         }
  44.         private void ellipseQuit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  45.         {
  46.             (sender as Ellipse).Tag = MouseButtonState.Pressed;
  47.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
  48.             ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
  49.             ellipseQuit.Height = ellipseQuit.Width = 48;
  50.             ellipseQuit.StrokeThickness = 5.5;
  51.             polylineQuit1.Points.Clear();
  52.             polylineQuit1.Points.Add(new Point(22.5, 22.5));
  53.             polylineQuit1.Points.Add(new Point(46.5, 46.5));
  54.             polylineQuit2.Points.Clear();
  55.             polylineQuit2.Points.Add(new Point(22.5, 46.5));
  56.             polylineQuit2.Points.Add(new Point(46.5, 22.5));
  57.         }
  58.         private void ellipseQuit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  59.         {
  60.             if ((MouseButtonState)(sender as Ellipse).Tag == MouseButtonState.Pressed)
  61.             {
  62.                 (sender as Ellipse).Tag = MouseButtonState.Released;
  63.                 LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
  64.                 ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
  65.                 ellipseQuit.Height = ellipseQuit.Width = 56;
  66.                 ellipseQuit.StrokeThickness = 6;
  67.                 polylineQuit1.Points.Clear();
  68.                 polylineQuit1.Points.Add(new Point(20, 20));
  69.                 polylineQuit1.Points.Add(new Point(49, 49));
  70.                 polylineQuit2.Points.Clear();
  71.                 polylineQuit2.Points.Add(new Point(20, 49));
  72.                 polylineQuit2.Points.Add(new Point(49, 20));
  73.                 Close();
  74.             }
  75.         }
  76.         private void ellipseQuit_MouseLeave(object sender, MouseEventArgs e)
  77.         {
  78.             (sender as Ellipse).Tag = MouseButtonState.Released;
  79.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
  80.             ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
  81.             ellipseQuit.Height = ellipseQuit.Width = 56;
  82.             ellipseQuit.StrokeThickness = 6;
  83.             polylineQuit1.Points.Clear();
  84.             polylineQuit1.Points.Add(new Point(20, 20));
  85.             polylineQuit1.Points.Add(new Point(49, 49));
  86.             polylineQuit2.Points.Clear();
  87.             polylineQuit2.Points.Add(new Point(20, 49));
  88.             polylineQuit2.Points.Add(new Point(49, 20));
  89.         }
  90.         private void ellipseQuit_MouseEnter(object sender, MouseEventArgs e)
  91.         {
  92.             (sender as Ellipse).Tag = MouseButtonState.Released;
  93.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
  94.             ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
  95.         }
  96.         private void ellipseAbout_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  97.         {
  98.             (sender as Ellipse).Tag = MouseButtonState.Pressed;
  99.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
  100.             ellipseAbout.Stroke = brush;
  101.             ellipseAbout.Height = ellipseAbout.Width = 48;
  102.             ellipseAbout.StrokeThickness = 5.5;
  103.         }
  104.         private void ellipseAbout_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  105.         {
  106.             if ((MouseButtonState)(sender as Ellipse).Tag == MouseButtonState.Pressed)
  107.             {
  108.                 (sender as Ellipse).Tag = MouseButtonState.Released;
  109.                 LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
  110.                 ellipseAbout.Stroke = brush;
  111.                 ellipseAbout.Height = ellipseAbout.Width = 56;
  112.                 ellipseAbout.StrokeThickness = 6;
  113.             }
  114.         }
  115.         private void ellipseAbout_MouseLeave(object sender, MouseEventArgs e)
  116.         {
  117.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
  118.             ellipseAbout.Stroke = brush;
  119.             ellipseAbout.Height = ellipseAbout.Width = 56;
  120.             ellipseAbout.StrokeThickness = 6;
  121.         }
  122.         private void ellipseAbout_MouseEnter(object sender, MouseEventArgs e)
  123.         {
  124.             (sender as Ellipse).Tag = MouseButtonState.Released;
  125.             LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
  126.             ellipseAbout.Stroke = brush;
  127.         }
  128.         private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  129.         {
  130.             (sender as Ellipse).Tag = MouseButtonState.Pressed;
  131.             ptEllipseMove = e.GetPosition(cnvCoordinate);
  132.             ptModifier = e.GetPosition((sender as Ellipse).Parent as IInputElement);
  133.             (sender as Ellipse).CaptureMouse();
  134.             
  135.         }
  136.         private void Ellipse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  137.         {
  138.             (sender as Ellipse).Tag = MouseButtonState.Released;
  139.             (sender as Ellipse).ReleaseMouseCapture();
  140.         }
  141.         private void Ellipse_MouseMove(object sender, MouseEventArgs e)
  142.         {
  143.             if ((MouseButtonState)(sender as Ellipse).Tag == MouseButtonState.Pressed)
  144.             {
  145.                 ptEllipseMove = e.GetPosition(cnvCoordinate);
  146.                 ptEllipsePositon = new Point(ptEllipseMove.X - ptModifier.X, ptEllipseMove.Y - ptModifier.Y);
  147.                 Point ptWindow = e.GetPosition(Application.Current.MainWindow);
  148.                 Point ptWindowPosition = new Point(ptWindow.X - ptModifier.X, ptWindow.Y - ptModifier.Y);
  149.                 if (ptWindowPosition.X < 0)
  150.                 {
  151.                     ptEllipsePositon.X = -24.5;
  152.                 }
  153.                 double maxPositonX = this.ActualWidth - (sender as Ellipse).Width;
  154.                 if (ptWindowPosition.X > maxPositonX)
  155.                 {
  156.                     ptEllipsePositon.X = maxPositonX - 24.5;
  157.                 }
  158.                 if (ptWindowPosition.Y < 20)
  159.                 {
  160.                     ptEllipsePositon.Y = -463;
  161.                 }
  162.                 double maxPositionY = this.ActualHeight - (sender as Ellipse).Height;
  163.                 if (ptWindowPosition.Y > maxPositionY)
  164.                 {
  165.                     ptEllipsePositon.Y = maxPositionY - 483;
  166.                 }
  167.                 Canvas.SetLeft(((sender as Ellipse).Parent as UIElement), ptEllipsePositon.X);
  168.                 Canvas.SetTop(((sender as Ellipse).Parent as UIElement), ptEllipsePositon.Y);
  169.             }
  170.         }
  171.         private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
  172.         {
  173.             (sender as Ellipse).Tag = MouseButtonState.Released;
  174.         }
  175.         private void Button_Click(object sender, RoutedEventArgs e)
  176.         {
  177.             if ((sender as Button).Name == "btnMinWindow")
  178.             {
  179.                 this.WindowState = WindowState.Minimized;
  180.             }
  181.             else
  182.             {
  183.                 this.Close();
  184.             }
  185.         }
  186.     }
  187. }