Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends i need some help to trigger pan event of the image in the picturebox..

Actually i have brightness event for left click and now i want panning event for right click on mouse
(the events are drag and brighten for left and same drag and pan for right clicks)

and here goes my code

if possible please help me with the zooming by mouse wheel , because my zooming code doesnot satisfy me
private bool _dragging = false;
    private Point _lastPosition = Point.Empty;
    private Point zoompoint = Point.Empty;
    private Point startingPoint = Point.Empty;
    private Point movingPoint = Point.Empty;
    private bool panning = false;
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            if (!_grayscale)
                return;

            _lastPosition = e.Location;
            _dragging = true;
        }
        else if (e.Button == MouseButtons.Right)
        {
            panning = true;
            startingPoint = new Point(e.Location.X - movingPoint.X, e.Location.Y - movingPoint.Y);



        }
    }
    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            _dragging = false;
        }
        else if (e.Button == MouseButtons.Right)
        {
            panning = false;
           }
    }

    private void pictureBox1_MouseLeave(object sender, EventArgs e)
    {
        _dragging = false;

    }

    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            if (!_dragging)
                return;

            _image.WindowWidth += e.X - _lastPosition.X;
            _image.WindowCenter += e.Y - _lastPosition.Y;

            _lastPosition = e.Location;

            DisplayImage(_image);
        }
        else if (e.Button == System.Windows.Forms.MouseButtons.Right )
        {
            if (panning)
            {
                movingPoint = new Point(e.Location.X - startingPoint.X,
                                        e.Location.Y - startingPoint.Y);
                pictureBox1.Invalidate();
            }
        }
    }
Posted

1 solution

Use this control instead:
ImageBox Control with Zoom/Pan Capability[^]
 
Share this answer
 
Comments
maheshwarreddy009 5-Jun-14 23:47pm    
i need center zoom my friend

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900