Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
C#
private void panel1_MouseWheel(object sender, MouseEventArgs e)
{
    if (sCDLST.Count > 0)
    {
        float z = Z;
        if (e.Delta > 0 && Z < 4) z += 0.1f;
        else if (e.Delta < 0 && Z > 1) z -= 0.1f;
        if (z != Z)
        {
            X = ((e.X + panel1.HorizontalScroll.Value) * z / Z - e.X);
            Z = z;
            Draw();
            panel1.AutoScrollMinSize = new Size((int)(bMP1.Width), 0);
            if (X < panel1.HorizontalScroll.Minimum) panel1.HorizontalScroll.Value = panel1.HorizontalScroll.Minimum;
            else if (X > panel1.HorizontalScroll.Maximum) panel1.HorizontalScroll.Value = panel1.HorizontalScroll.Maximum;
            else panel1.HorizontalScroll.Value = (int)X; //Problem : always zero
        }
    }
}

z:      new zoom factor
Z:      old zoom factor
Draw(): Redraw bMP1 based on new zoom factor


Hello everybody!

Here is the code that when user rotates the mouse wheel, "fixed-zoom in/out" will be performed. Then it will redraw the bitmap according to the new factor. The problem is that I cannot update the panel1.HorizontalScroll.Value

Thanks!
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900