|
-
October 28th, 2010, 04:06 AM
#1
Need help in event handling (WPF Application)
Hey guys (: I'm currently working on this project which consists of zoom function. Now, I am facing this problem where the zoom function that used by me required four mouse events, which are Mouse wheel, Mouse left button up, down etc. However, I am trying to make it like when a button is clicked, the zoom function can be carried out eventually. However, I faced problem in calling mouse event functions using button. Here is the code, please help me out (: thanks alot DDDDD
private void image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
imagePicture.CaptureMouse();
var tt = (TranslateTransform)((TransformGroup)imagePicture.RenderTransform).Children.First(tr => tr is TranslateTransform);
start = e.GetPosition(border);
origin = new Point(tt.X, tt.Y);
}
private void image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
imagePicture.ReleaseMouseCapture();
}
private void image_MouseMove(object sender, MouseEventArgs e)
{
if (!imagePicture.IsMouseCaptured) return;
var tt = (TranslateTransform)((TransformGroup)imagePicture.RenderTransform).Children.First(tr => tr is TranslateTransform);
Vector v = start - e.GetPosition(border);
tt.X = origin.X - v.X;
tt.Y = origin.Y - v.Y;
}
private void image_mousewheel(object sender, MouseWheelEventArgs e)
{
TransformGroup transformGroup = (TransformGroup)imagePicture.RenderTransform;
ScaleTransform transform = (ScaleTransform)transformGroup.Children[0];
RenderOptions.SetBitmapScalingMode(imagePicture, BitmapScalingMode.NearestNeighbor);
double zoom = e.Delta > 0 ? .01 : -.01;
transform.ScaleX += zoom;
transform.ScaleY += zoom;
}
Again, my question is How am i going to execute those four mouse event function ONLY WHEN THE BUTTON IS CLICKED, instead of being able to zoom straight when the mouse is brought to the image. For you info, the name of the image is called(image). I've tried binding method, unfortunately it doesn't work;(
Regards.
-
October 28th, 2010, 01:27 PM
#2
Re: Need help in event handling (WPF Application)
However, I faced problem in calling mouse event functions using button
That's because that is the wrong way to go about it. You should simply set some flag (i.e., "zooming = true;") when the button is pressed. Your mouse handlers will only initiate zooming functions if this flag is true. Otherwise they simply return and do nothing.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|