Need help on putting a function into a button
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Need help on putting a function into a button

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Talking Need help on putting a function into a button

    Hi all,

    I am using both Expression Blend and Visual studio to work on my project.I did a zoom function and i want to place it into a button,so whenever the user click on the button the zoom function will be activated.The problem is i don't how to implement it . Thank in advance those who helped me.


    Below is the code for my zoom function.

    public MainWindow()
    {
    this.InitializeComponent();

    TransformGroup group = new TransformGroup();

    ScaleTransform xform = new ScaleTransform();
    group.Children.Add(xform);

    TranslateTransform tt = new TranslateTransform();
    group.Children.Add(tt);

    imagePicture.RenderTransform = group;

    imagePicture.MouseWheel += image_mousewheel;
    imagePicture.MouseLeftButtonDown += image_MouseLeftButtonDown;
    imagePicture.MouseLeftButtonUp += image_MouseLeftButtonUp;
    imagePicture.MouseMove += image_MouseMove;
    }


    public 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);

    }


    public void image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
    imagePicture.ReleaseMouseCapture();
    }

    public 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;
    }



    The code appear in visual studio when the button is created

    private void Zoom(object sender, RoutedEventArgs Args)
    {

    }


    Basically i want to put the zoom function codes into the button.

  2. #2
    Join Date
    Oct 2010
    Posts
    2

    Re: Need help on putting a function into a button

    Sorry i made a mistake on the codes for my zoom function, this is the correct one.


    public MainWindow()
    {
    this.InitializeComponent();

    TransformGroup group = new TransformGroup();

    ScaleTransform xform = new ScaleTransform();
    group.Children.Add(xform);

    TranslateTransform tt = new TranslateTransform();
    group.Children.Add(tt);

    imagePicture.RenderTransform = group;

    imagePicture.MouseWheel += image_mousewheel;
    imagePicture.MouseLeftButtonDown += image_MouseLeftButtonDown;
    imagePicture.MouseLeftButtonUp += image_MouseLeftButtonUp;
    imagePicture.MouseMove += image_MouseMove;
    }


    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;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center