Reputation: 141
I have a windows forms project in which I want to implement scrolling. I attempted to use the second answer from this question
so now my code looks like this:
void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta != 0)
{
if (e.Delta <= 0)
{
//set minimum size to zoom
if (pictureBox1.Width < 50)
return;
}
else
{
//set maximum size to zoom
if (pictureBox1.Width > 500)
return;
}
pictureBox1.Width += Convert.ToInt32(pictureBox1.Width * e.Delta / 1000);
pictureBox1.Height += Convert.ToInt32(pictureBox1.Height * e.Delta / 1000);
}
but it only behaves like this
Upvotes: 3
Views: 665
Reputation: 813
This depends on the SizeMode of your PictureBox. By default, this is the enum Normal
. Given your demonstration, I suggest you use the Zoom
enum value for the image to grow and shrink with your mouse wheel as the picture box is resized.
Upvotes: 1