WPF Mouse-3-

索引サイト

コントロールキー併用
移動は Window 自体を移動する。大きさはホイールで調整




using System.Windows.Media.Animation;

namespace WpfApplication2
{
///


/// MainWindow.xaml の相互作用ロジック
///

public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Left = 0;
this.Top = 0;
sliderView.Opacity = 0;
stackPanel1.Opacity = 0;
stackPanel2.Opacity = 0;
stackPanel3.Opacity = 0;
stackPanel4.Opacity = 0;
}
Int16 z_move = 0;
private void Window_MouseMove(object sender, MouseEventArgs e)
{
UIElement w_uie = sender as UIElement;
Point w_point = e.GetPosition(w_uie);
textBlockX_Mouse.Text = "Mouse X: " + w_point.X;
textBlockY_Mouse.Text = "Mouse Y: " + w_point.Y;
if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
{
if (z_move == 1)
{
this.Left = z_left + (this.Left + w_point.X - z_screenX);
this.Top = z_top + (this.Top + w_point.Y - z_screenY);
}
}
}
Double z_screenX = 0;
Double z_screenY = 0;
Double z_left = 0;
Double z_top = 0;
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
UIElement w_uie = sender as UIElement;
Point w_point = e.GetPosition(w_uie);

textBlockX_WindowPos.Text = "WindowPos X: " + w_point.X;
textBlockY_WindowPos.Text = "WindowPos Y: " + w_point.Y;

z_screenX = w_point.X + this.Left;
z_screenY = w_point.Y + this.Top;

textBlockX_Center.Text = "Screen X: " + z_screenX;
textBlockY_Center.Text = "Screen Y: " + z_screenY;

z_left = this.Left;
z_top = this.Top;

textBlockX_Window.Text = "this.left: " + this.Left;
textBlockY_Window.Text = "this.top : " + this.Top;

if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
{
z_move = 1;
}
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
{
z_move = 0;
}
if (e.Key == Key.Escape)
{
Environment.Exit(0);
}
}
private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
{
if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
{
if ((Keyboard.Modifiers & ModifierKeys.Control) > 0)
{
double w_view = sliderView.Value += e.Delta / 28;
sliderView.BeginAnimation(Slider.ValueProperty, new DoubleAnimation(w_view, new TimeSpan(0, 0, 0)));
}
}
}
}
}




AX