Масштабирование изображения с помощью колесика мыши.

В приведенном ниже коде я пытаюсь увеличить изображение с помощью колесика мыши. Но код не работает должным образом, он просто обновляет панель, но не меняет ее размер. На самом деле я беру изображение из потока памяти, созданного другим классом, называемым decrypt. Полное изображение отображается правильно, но я не могу выполнить масштабирование изображения с помощью события колесика мыши. Пожалуйста, помогите мне.

private void Form2_Load(object sender, EventArgs e)
{
    this.Width = Screen.PrimaryScreen.WorkingArea.Width;
    this.Height = Screen.PrimaryScreen.WorkingArea.Height;
    this.CenterToScreen();
    PicturePanel= new PictureBox();

    PicturePanel.Dock = DockStyle.Fill;
    //PicturePanel.SizeMode = PictureBoxSizeMode.AutoSize;

    //PicturePanel.SizeMode = PictureBoxSizeMode.CenterImage;
    PicturePanel.Focus();
    //PicturePanel.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.OnMouseWheel);
    this.Controls.Add(PicturePanel);


    View_codee v = new View_codee();

    try
    {
        PicturePanel.Image = Image.FromStream(Decrypt.ms1);
    }
    catch (Exception ee)
    {
        MessageBox.Show(ee.Message);
    }
    this.Name = "";
} 



protected override void OnMouseWheel(MouseEventArgs mea)
{
    // Override OnMouseWheel event, for zooming in/out with the scroll wheel
    if (PicturePanel.Image != null)
    {
        // If the mouse wheel is moved forward (Zoom in)
        if (mea.Delta > 0)
        {
            // Check if the pictureBox dimensions are in range (15 is the minimum and maximum zoom level)
            if ((PicturePanel.Width < (15 * this.Width)) && (PicturePanel.Height < (15 * this.Height)))
            {
                // Change the size of the picturebox, multiply it by the ZOOMFACTOR
                PicturePanel.Width = (int)(PicturePanel.Width * 1.25);
                PicturePanel.Height = (int)(PicturePanel.Height * 1.25);

                // Formula to move the picturebox, to zoom in the point selected by the mouse cursor
                PicturePanel.Top = (int)(mea.Y - 1.25 * (mea.Y - PicturePanel.Top));
                PicturePanel.Left = (int)(mea.X - 1.25 * (mea.X - PicturePanel.Left));
            }
        }
        else
        {
            // Check if the pictureBox dimensions are in range (15 is the minimum and maximum zoom level)
            if ((PicturePanel.Width > (this.Width / 15)) && (PicturePanel.Height > (this.Height / 15)))
            {
                // Change the size of the picturebox, divide it by the ZOOMFACTOR
                PicturePanel.Width = (int)(PicturePanel.Width / 1.25);
                PicturePanel.Height = (int)(PicturePanel.Height / 1.25);

                // Formula to move the picturebox, to zoom in the point selected by the mouse cursor
                PicturePanel.Top = (int)(mea.Y - 0.80 * (mea.Y - PicturePanel.Top));
                PicturePanel.Left = (int)(mea.X - 0.80 * (mea.X - PicturePanel.Left));
            }
        }
    }
}      

Ответы на вопрос(1)

Ваш ответ на вопрос