Hello,
I have some troubles with scrolling. I have a picture box, and I would like to be able to zoom and scroll with a combination of mouse whell + ctrl/alt. The zooming part works fine. I was able to get the key controls, but I have troubles moving the scrollbars. I tried to use the HorizontalScroll properties, the value is changed fine when I do the required combination, but nothing happens on the main window... Here is the code I have. The windows form has autoscroll set to false.
protected override void OnMouseWheel(MouseEventArgs mea)
{
if (ctrlDown && !shiftDown && pictureBox1.Image!=null)
{
// If the mouse wheel is moved forward (Zoom in)
if (mea.Delta > 0 && zoomValue <= 5)
{
zoomValue += 0.2;
pictureBox1.Width = (int)(pictureBox1.Width * 1.25);
pictureBox1.Height = (int)(pictureBox1.Height * 1.25);
//pictureBox1.Top = (int)(mea.Y - 1.25 * (mea.Y - pictureBox1.Top));
//pictureBox1.Left = (int)(mea.X - 1.25 * (mea.X - pictureBox1.Left));
pictureBox1.Image = PictureBoxZoom(bmpPictureBox, zoomValue);
}
//Zoom out
else if (mea.Delta < 0 && zoomValue > 0.8)
{
zoomValue -= 0.2;
pictureBox1.Width = (int)(pictureBox1.Width / 1.25);
pictureBox1.Height = (int)(pictureBox1.Height / 1.25);
//pictureBox1.Top = (int)(mea.Y - 0.80 * (mea.Y - pictureBox1.Top));
//pictureBox1.Left = (int)(mea.X - 0.80 * (mea.X - pictureBox1.Left));
pictureBox1.Image = PictureBoxZoom(bmpPictureBox, zoomValue);
}
}
else if (shiftDown && !ctrlDown && pictureBox1.Image != null)
{
if (HorizontalScroll.Value + System.Math.Sign(mea.Delta)*10 < HorizontalScroll.Minimum)
{ HorizontalScroll.Value = HorizontalScroll.Minimum; }
else if (HorizontalScroll.Value + System.Math.Sign(mea.Delta) * 10 > HorizontalScroll.Maximum)
{ HorizontalScroll.Value = HorizontalScroll.Maximum; }
else { HorizontalScroll.Value += System.Math.Sign(mea.Delta) * 10; }
}
Refresh();
}
Thanks!