如何通过右键单击在Picturebox上触发缩放和平移事件 [英] How Do I Trigger A Zoom And Pan Event On Picturebox With Right Click

查看:207
本文介绍了如何通过右键单击在Picturebox上触发缩放和平移事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友我需要一些帮助来触发图片框中图像的泛事件..



实际上我有左击的亮度事件现在我想要平移右键单击鼠标的事件

(左侧拖动和变亮,右键单击拖动和平移)



和这里转到我的代码



如果可能请帮助我用鼠标滚轮缩放,因为我的缩放代码不满足我

 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)
返回;

_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();
}
}
}

解决方案

改为使用此控件:

具有缩放/平移功能的ImageBox控件 [ ^ ]

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

解决方案

Use this control instead:
ImageBox Control with Zoom/Pan Capability[^]


这篇关于如何通过右键单击在Picturebox上触发缩放和平移事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆