Window1.xaml.cs
上传用户:haomiao527
上传日期:2008-10-28
资源大小:322k
文件大小:9k
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace CShap.Wpf.EinsteinSuperQuestion
- {
- /// <summary>
- /// Window1.xaml 的交互逻辑
- /// </summary>
- public partial class Window1 : Window
- {
- Point ptEllipseMove, ptEllipsePositon, ptModifier;
- public Window1()
- {
- InitializeComponent();
- }
- protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
- {
- base.OnMouseLeftButtonDown(e);
- if (grdCaption.Equals(e.Source as Grid))
- {
- this.DragMove();
- }
- }
- private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
- {
- LinearGradientBrush brush = new LinearGradientBrush(Colors.White, Colors.Yellow, new Point(0.5, 0), new Point(0.5, 0.5));
- (sender as TextBlock).Foreground = brush;
- }
- private void TextBlock_MouseLeave(object sender, MouseEventArgs e)
- {
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.GreenYellow, new Point(0.5, 0), new Point(0.5, 0.3));
- (sender as TextBlock).Foreground = brush;
- }
- private void ellipseQuit_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Pressed;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
- ellipseQuit.Height = ellipseQuit.Width = 48;
- ellipseQuit.StrokeThickness = 5.5;
- polylineQuit1.Points.Clear();
- polylineQuit1.Points.Add(new Point(22.5, 22.5));
- polylineQuit1.Points.Add(new Point(46.5, 46.5));
- polylineQuit2.Points.Clear();
- polylineQuit2.Points.Add(new Point(22.5, 46.5));
- polylineQuit2.Points.Add(new Point(46.5, 22.5));
- }
- private void ellipseQuit_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- if ((MouseButtonState)(sender as Ellipse).Tag == MouseButtonState.Pressed)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
- ellipseQuit.Height = ellipseQuit.Width = 56;
- ellipseQuit.StrokeThickness = 6;
- polylineQuit1.Points.Clear();
- polylineQuit1.Points.Add(new Point(20, 20));
- polylineQuit1.Points.Add(new Point(49, 49));
- polylineQuit2.Points.Clear();
- polylineQuit2.Points.Add(new Point(20, 49));
- polylineQuit2.Points.Add(new Point(49, 20));
- Close();
- }
- }
- private void ellipseQuit_MouseLeave(object sender, MouseEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
- ellipseQuit.Height = ellipseQuit.Width = 56;
- ellipseQuit.StrokeThickness = 6;
- polylineQuit1.Points.Clear();
- polylineQuit1.Points.Add(new Point(20, 20));
- polylineQuit1.Points.Add(new Point(49, 49));
- polylineQuit2.Points.Clear();
- polylineQuit2.Points.Add(new Point(20, 49));
- polylineQuit2.Points.Add(new Point(49, 20));
- }
- private void ellipseQuit_MouseEnter(object sender, MouseEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseQuit.Stroke = polylineQuit1.Stroke = polylineQuit2.Stroke = brush;
- }
- private void ellipseAbout_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Pressed;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseAbout.Stroke = brush;
- ellipseAbout.Height = ellipseAbout.Width = 48;
- ellipseAbout.StrokeThickness = 5.5;
- }
- private void ellipseAbout_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- if ((MouseButtonState)(sender as Ellipse).Tag == MouseButtonState.Pressed)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseAbout.Stroke = brush;
- ellipseAbout.Height = ellipseAbout.Width = 56;
- ellipseAbout.StrokeThickness = 6;
- }
- }
- private void ellipseAbout_MouseLeave(object sender, MouseEventArgs e)
- {
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseAbout.Stroke = brush;
- ellipseAbout.Height = ellipseAbout.Width = 56;
- ellipseAbout.StrokeThickness = 6;
- }
- private void ellipseAbout_MouseEnter(object sender, MouseEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- LinearGradientBrush brush = new LinearGradientBrush(Colors.Black, Colors.Red, new Point(0.5, 0), new Point(0.5, 0.5));
- ellipseAbout.Stroke = brush;
- }
- private void Ellipse_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Pressed;
- ptEllipseMove = e.GetPosition(cnvCoordinate);
- ptModifier = e.GetPosition((sender as Ellipse).Parent as IInputElement);
- (sender as Ellipse).CaptureMouse();
-
- }
- private void Ellipse_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- (sender as Ellipse).ReleaseMouseCapture();
- }
- private void Ellipse_MouseMove(object sender, MouseEventArgs e)
- {
- if ((MouseButtonState)(sender as Ellipse).Tag == MouseButtonState.Pressed)
- {
- ptEllipseMove = e.GetPosition(cnvCoordinate);
- ptEllipsePositon = new Point(ptEllipseMove.X - ptModifier.X, ptEllipseMove.Y - ptModifier.Y);
- Point ptWindow = e.GetPosition(Application.Current.MainWindow);
- Point ptWindowPosition = new Point(ptWindow.X - ptModifier.X, ptWindow.Y - ptModifier.Y);
- if (ptWindowPosition.X < 0)
- {
- ptEllipsePositon.X = -24.5;
- }
- double maxPositonX = this.ActualWidth - (sender as Ellipse).Width;
- if (ptWindowPosition.X > maxPositonX)
- {
- ptEllipsePositon.X = maxPositonX - 24.5;
- }
- if (ptWindowPosition.Y < 20)
- {
- ptEllipsePositon.Y = -463;
- }
- double maxPositionY = this.ActualHeight - (sender as Ellipse).Height;
- if (ptWindowPosition.Y > maxPositionY)
- {
- ptEllipsePositon.Y = maxPositionY - 483;
- }
- Canvas.SetLeft(((sender as Ellipse).Parent as UIElement), ptEllipsePositon.X);
- Canvas.SetTop(((sender as Ellipse).Parent as UIElement), ptEllipsePositon.Y);
- }
- }
- private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
- {
- (sender as Ellipse).Tag = MouseButtonState.Released;
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- if ((sender as Button).Name == "btnMinWindow")
- {
- this.WindowState = WindowState.Minimized;
- }
- else
- {
- this.Close();
- }
- }
- }
- }