这个问题之前被问过,但既然它不起作用,我缺乏声望点(我试着评论问题,但我不能),我不得不再次提出这个问题。如何放大c#中的picturebox中的一个点?
这是以前问的问题的链接; How to zoom at a point in picturebox
我使用了链接中显示的代码,但是当我运行它时,点或形状消失了。
这是我的代码;
public partial class Form1 : Form
{
private Matrix transform = new Matrix();
private double m_dZoomscale = 1.0;
public static double s_dScrollValue = .1;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Transform = transform;
Pen mypen = new Pen(Color.Red,5);
Rectangle rect = new Rectangle(10, 10, 30, 30);
e.Graphics.DrawRectangle(mypen, rect);
}
protected override void OnMouseWheel(MouseEventArgs mea)
{
pictureBox1.Focus();
if (pictureBox1.Focused == true && mea.Delta != 0)
{
ZoomScroll(mea.Location, mea.Delta > 0);
}
}
private void ZoomScroll(Point location, bool zoomIn)
{
transform.Translate(-location.X, -location.Y);
if (zoomIn)
transform.Scale((float)s_dScrollValue, (float)s_dScrollValue);
else
transform.Scale((float)-s_dScrollValue, (float)-s_dScrollValue);
transform.Translate(location.X, location.Y);
pictureBox1.Invalidate();
}
也许你没有添加'pictureBox1_Paint'方法为你的'pictureBox1.Paint'事件的处理程序? – Pikoh
感谢您的回复Pikoh。我怎么做到这一点?如果你说添加油漆选项(从属性/事件)作为'pictureBox1_Paint',我做到了。 – Quanthema