Click here to Skip to main content
15,921,467 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
i want to Zoom In and Zoom Out when user mouse wheel in the C#.net. It is an Windows Application . Please Help me.
Posted
Updated 27-Feb-22 9:13am
Comments
Sergey Alexandrovich Kryukov 30-Nov-11 2:55am    
So, scroll or zoom? I guess both...
--SA

Just as Griff said in his solution
Quote:
The PictureBox can never have the input focus[...]


But nosy as I am I tried this:

C#
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
pictureBox1.MouseHover += new EventHandler(pictureBox1_MouseHover);

void pictureBox1_MouseHover(object sender, EventArgs e)
{
    pictureBox1.Focus();
}


void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
    // here I can use e.Delta        
}


Did not check for pitfalls in using MouseHover to get focus. Just an idea...
 
Share this answer
 
v2
Comments
naraayanan 3-Dec-11 1:25am    
Hi,
Thanks for your mail
You can't, without hooking the MouseWheel messages.

You can add a handler for the event (by writing the code in your form load event handler - it is masked in the designer) but it will never occur. The reason? The PictureBox can never have the input focus, so can never obey mouse wheel commands. So, no event in the designer, no event when the app runs.
Try this: Add a panel, and give it a MouseWheel handler. Make it print to the console. Try it. Nothing happens.
Add a textbox to the panel. Try again. When the textbox has the focus, you get mouse wheel events.

Try and think of another way to do your zoom, it will be much easier!
 
Share this answer
 
Comments
Michel [mjbohn] 30-Nov-11 3:50am    
I use MouseHover to get PictureBox focused. Please see my solution. What do you think about?
naraayanan 3-Dec-11 1:25am    
Hi,
Thanks for your mail
I use TrackBar to capture wheel mouse event, like below:

1- Add a TrackBar control to the form.

2- Set Scroll event to the TrackBar.

private void TrackBar1_Scroll(object sender, EventArgs e)
        {
            try
            {
                ... do something with the TrackBar1.value.
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 
Share this answer
 
v2

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