C# 在picturebox控件里实现用鼠标滚轮让图片上下翻页,按住ctrl键加鼠标滚轮实现图片放大缩小

想要实现picturebox控件里面用鼠标滚轮让图片上下翻页和按住ctrl键加鼠标滚轮实现图片放大缩小这两个功能,就要借助于picturebox控件中的三个事件。

第一个是pictureBox1_KeyUp。

第二个是pictureBox1_KeyDown。

第三个是PictureBox1_MouseWheel

下面直接上代码就可以了:

private void pictureBox1_KeyUp(object sender, KeyEventArgs e)//判断是否按下ctrl键

{

//throw new NotImplementedException();

if (e.KeyCode == Keys.ControlKey)//抬起ctrl键

{

n = 0;

//MessageBox.Show("....dada");

}

}

private void pictureBox1_KeyDown(object sender, KeyEventArgs e)//判断是否抬起ctrl键

{

//throw new NotImplementedException();

if (e.KeyCode == Keys.ControlKey)//按下ctrl键

{

n = 1;

//MessageBox.Show("....dada");

}

}

private void PictureBox1_MouseWheel(object sender, MouseEventArgs e)

{

//throw new NotImplementedException();

if (e.Delta > 0 && n != 1)//滚轮向上翻页

{

button4.PerformClick();

if (i <= 0)

{

//MessageBox.Show("已经是第一个图片了");

i++;

}

if (i > 0)

{

i--;

}

if (i >= 0 && i < images.Count)

{

pictureBox1.Image = images[i];

}

}

if (e.Delta <= 0 && n != 1)//滚轮向下翻页

{

button5.PerformClick();

if (i < images.Count)

{

i++;

}

if (i < images.Count && i >= 0)

{

pictureBox1.Image = images[i];

}

else

{

//MessageBox.Show("已经是最后的图片了");

i--;

}

}

if (e.Delta > 0 && n == 1)//滚轮放大图片

{

pictureBox1.Width = (int)(pictureBox1.Width * 1.1);

pictureBox1.Height = (int)(pictureBox1.Height * 1.1);

}

if (e.Delta <= 0 && n == 1)//滚轮缩小图片

{

pictureBox1.Width = (int)(pictureBox1.Width * 0.9);

pictureBox1.Height = (int)(pictureBox1.Height * 0.9);

}

}

大家应该都能看懂,有问题大家可以私信联系我。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑さん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值