/ Create a simple red cross as a bitmap and display it in the pictureboxīitmap bmp = new Bitmap(OuterPanel.Width, OuterPanel.Height, .Format16bppRgb555) OuterPanel.MouseWheel += new MouseEventHandler(PicBox_MouseWheel) PicBox.MouseEnter += new EventHandler(PicBox_MouseEnter) OuterPanel.MouseEnter += new EventHandler(PicBox_MouseEnter) PicBox.SizeMode = PictureBoxSizeMode.StretchImage / Special settings for the picturebox ctrl / Supported fileformat: *.gif, *.tif, *.jpg, *.bmp / Complete filename of the picture, including path information / file doesn´t exist or we receive an exception, the picturebox displays / Property to select the picture which is displayed in the picturebox. InitCtrl() // my special settings for the ctrl Private int MINMAX = 5 // 5 times bigger or smaller than the ctrl Private double ZOOMFACTOR = 1.25 // = 25% smaller or larger
#WHY IS MY SCROLL WHEEL ZOOMING CODE#
Updated code by adding a new ImageProperty so you can set directly the Image public class PictureBox : PicturePanel.Left = (int)(mea.X - 0.80 * (mea.X - PicturePanel.Left)) PicturePanel.Top = (int)(mea.Y - 0.80 * (mea.Y - PicturePanel.Top)) Formula to move the picturebox, to zoom in the point selected by the mouse cursor PicturePanel.Height = (int)(PicturePanel.Height / 1.25) PicturePanel.Width = (int)(PicturePanel.Width / 1.25) Change the size of the picturebox, divide it by the ZOOMFACTOR If ((PicturePanel.Width (this.Width / 15)) & (PicturePanel.Height > (this.Height / 15))) Check if the pictureBox dimensions are in range (15 is the minimum and maximum zoom level) If the mouse wheel is moved forward (Zoom in) Override OnMouseWheel event, for zooming in/out with the scroll wheel Protected override void OnMouseWheel(MouseEventArgs mea) PicturePanel.Image = Image.FromStream(Decrypt.ms1)
PicturePanel.MouseWheel += new (this.OnMouseWheel)
PicturePanel.SizeMode = PictureBoxSizeMode.AutoSize private void Form2_Load(object sender, EventArgs e) Complete Image is displayed properly but I am not able to performing zooming of the image using mousewheel event. Actually I am taking the image from memory stream that is created by another class called as decrypt. But the code is not working properly, it is just refreshing the panel but it does not resize it. In the code below I am trying to zoom the image via a mouse wheel.