- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- 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 WpfTkr
- {
- /// <summary>
- /// Interaction logic for Facility.xaml
- /// </summary>
- public partial class Facility : UserControl
- {
- MainWindow wnd;
- Point lastPos;
- public Facility()
- {
- InitializeComponent();
- }
- public Facility(MainWindow wnd, string name): this()
- {
- this.wnd = wnd;
- this.lastPos = default(Point);
- this.txtName.Text = name;
- }
- private void Border_MouseEnter(object sender, MouseEventArgs e)
- {
- var brd = sender as Border;
- brd.BorderBrush = new SolidColorBrush(Colors.Red);
- LayoutButtons.Visibility = Visibility.Visible;
- }
- private void Border_MouseLeave(object sender, MouseEventArgs e)
- {
- var brd = sender as Border;
- brd.BorderBrush = new SolidColorBrush(Colors.Black);
- lastPos = default(Point);
- LayoutButtons.Visibility = Visibility.Collapsed;
- }
- private void Border_MouseMove(object sender, MouseEventArgs e)
- {
- if(wnd.btnMove.IsChecked == true && lastPos != default(Point))
- {
- var pos = e.GetPosition(wnd.LayoutFacility);
- var dx = pos.X - lastPos.X;
- var dy = pos.Y - lastPos.Y;
- var x = (double)this.GetValue(Canvas.LeftProperty) + dx;
- var y = (double)this.GetValue(Canvas.TopProperty) + dy;
- this.SetValue(Canvas.LeftProperty, x);
- this.SetValue(Canvas.TopProperty, y);
- lastPos = pos;
- }
- }
- private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- lastPos = e.GetPosition(wnd.LayoutFacility);
- }
- private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- lastPos = default(Point);
- }
- private void btnSettings_Click(object sender, RoutedEventArgs e)
- {
- var opt = new FacilityOptions(this);
- opt.ShowDialog();
- }
- private void btnRemove_Click(object sender, RoutedEventArgs e)
- {
- wnd.LayoutFacility.Children.Remove(this);
- }
- }
- }
суббота, 2 июня 2012 г.
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий