C#中,滚动鼠标滚轮时,图片以鼠标点为中心,进行放大缩小,给出代码
我写的代码可以放大缩小,但是缩小之后,跑到左上角去了
代码如下:
private void test_MouseWheel(object sender, MouseEventArgs e)
{
System.Drawing.Size t = pbSample.Size;
t.Width += (int)(e.Delta*1.1f);
t.Height += (int)(e.Delta * 1.1f);
//设置最小显示大小
if (t.Width < 40)
t.Width = 40;
if (t.Height < 30)
t.Height = 30;
//设置最大显示大小
if (t.Width >1000)
t.Width = 1000;
if (t.Height > 850)
t.Height = 850;
pbSample.Width = t.Width;
pbSample.Height = t.Height;
}