1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| 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 WpfCanvasBoard
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private Point startPoint;
private Point endPoint;
private void chart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!chart.IsMouseCaptured)
{
startPoint = e.GetPosition(chart);
chart.CaptureMouse();
chart.Cursor = Cursors.Hand;
}
}
private void chart_MouseMove(object sender, MouseEventArgs e)
{
if (chart.IsMouseCaptured)
{
endPoint = e.GetPosition(chart);
Canvas.SetLeft(chart, endPoint.X);
Canvas.SetTop(chart, endPoint.Y);
}
}
private void chart_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
if (chart.IsMouseCaptured)
{
endPoint = e.GetPosition(chart);
Canvas.SetLeft(chart, endPoint.X);
Canvas.SetTop(chart, endPoint.Y);
chart.ReleaseMouseCapture();
chart.Cursor = Cursors.Arrow;
}
}
int zoom = 100;
int increment = 2;
private void chart_MouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta ==120)
{
zoom += increment;
zoom = Math.Min(zoom, 150);
}
else if (e.Delta == -120)
{
zoom -= increment;
zoom = Math.Max(zoom, 1);
}
sc.ScaleX =(double) zoom / 100.0;
sc.ScaleY =(double) zoom / 100.0;
}
private void btnReset_Click(object sender, RoutedEventArgs e)
{
sc.ScaleX = 1.0;
sc.ScaleY = 1.0;
Canvas.SetLeft(chart, 0.0);
Canvas.SetTop(chart, 0.0);
}
}
} |
Partager