Real coordinates for graph inside viewport relative to mouse coordinates

大城市里の小女人 提交于 2019-12-06 15:18:53

Maybe this will help:

PointF ScaleUnscale(PointF p, float offX, float offY, float sX, float sY, bool scale)
{
    PointF pf = p;

    if (scale)
    {
        pf = new PointF( ( p.X  - offX )/ sX, (p.Y - offY)/ sY) ;
    }
    else
    {
        pf = new PointF( p.X * sX + offX, p.Y * sY + offY);
    }
    return pf;
}

This scales a mouse point to a canvas point or back:

cPoints.Add(ScaleUnscale(e.Location, .., true));

Tested with a translated and scaled Graphics object:

g.TranslateTransform(offX, offY);
g.ScaleTransform(scaleX, scaleY);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!