суббота, 2 июня 2012 г.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15.  
  16. namespace WpfTkr
  17. {
  18.     /// <summary>
  19.     /// Interaction logic for Facility.xaml
  20.     /// </summary>
  21.     public partial class Facility : UserControl
  22.     {
  23.         MainWindow wnd;
  24.         Point lastPos;
  25.  
  26.         public Facility()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.         public Facility(MainWindow wnd, string name): this()
  32.         {
  33.             this.wnd = wnd;
  34.             this.lastPos = default(Point);
  35.             this.txtName.Text = name;
  36.         }
  37.  
  38.         private void Border_MouseEnter(object sender, MouseEventArgs e)
  39.         {
  40.             var brd = sender as Border;
  41.  
  42.             brd.BorderBrush = new SolidColorBrush(Colors.Red);
  43.  
  44.             LayoutButtons.Visibility = Visibility.Visible;
  45.         }
  46.  
  47.         private void Border_MouseLeave(object sender, MouseEventArgs e)
  48.         {
  49.             var brd = sender as Border;
  50.  
  51.             brd.BorderBrush = new SolidColorBrush(Colors.Black);
  52.             lastPos = default(Point);
  53.  
  54.             LayoutButtons.Visibility = Visibility.Collapsed;
  55.         }
  56.  
  57.         private void Border_MouseMove(object sender, MouseEventArgs e)
  58.         {
  59.             if(wnd.btnMove.IsChecked == true && lastPos != default(Point))
  60.             {
  61.                 var pos = e.GetPosition(wnd.LayoutFacility);
  62.                 var dx = pos.X - lastPos.X;
  63.                 var dy = pos.Y - lastPos.Y;
  64.                 var x = (double)this.GetValue(Canvas.LeftProperty) + dx;
  65.                 var y = (double)this.GetValue(Canvas.TopProperty) + dy;
  66.  
  67.                 this.SetValue(Canvas.LeftProperty, x);
  68.                 this.SetValue(Canvas.TopProperty, y);
  69.  
  70.                 lastPos = pos;
  71.             }
  72.         }
  73.  
  74.         private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  75.         {
  76.             lastPos = e.GetPosition(wnd.LayoutFacility);
  77.         }
  78.  
  79.         private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  80.         {
  81.             lastPos = default(Point);
  82.         }
  83.  
  84.         private void btnSettings_Click(object sender, RoutedEventArgs e)
  85.         {
  86.             var opt = new FacilityOptions(this);
  87.  
  88.             opt.ShowDialog();
  89.         }
  90.  
  91.         private void btnRemove_Click(object sender, RoutedEventArgs e)
  92.         {
  93.             wnd.LayoutFacility.Children.Remove(this);
  94.         }
  95.  
  96.     }
  97. }

Комментариев нет:

Отправить комментарий