How to use Mouse_Wheel to zoom in & out pictureBox ...
i use this code :
namespace Test_Code_Csharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.MouseWheel += new MouseEventHandler(pictureBox1_MouseWheel);
}
void pictureBox1_MouseWheel(object sender, MouseEventArgs e)
{
pictureBox1.Height += e.Delta / 60;
pictureBox1.Width += e.Delta / 60;
pictureBox1.Top -= e.Delta / 120;
pictureBox1.Left -= e.Delta / 120;
}
But no happen ! no error ! and no ...
Loading


VulpesRank #55 · 29.2K reputationPosted Sep 3, 2014, 5:18 AM EDT
When I tried it myself, I added the MouseEnter event through the Properties Box at design time.
When I subsequently posted it, I added the event dynamically instead as that's what you'd done for the MouseWheel event. Unfortunately, I forgot that MouseEnter is an EventHandler rather than a MouseEventHandler delegate.
If you change:
VulpesRank #55 · 29.2K reputationPosted Sep 2, 2014, 9:32 AM EDT
The problem with pictureboxes is that they don't normally receive focus even when they're clicked so the trick is to force focus onto them when (say) the mouse moves over them. The MouseWheel event will then fire.
You also need to set the picturebox's SizeMode property to zoom when its size changes.
Try this:
ghasem dehRank #8,160 · 227 reputationPosted Sep 2, 2014, 11:29 PM EDT
use this But : error in MouseEnter Method ...
and when use just pictureBox1.Focus ...
not happen !
VulpesRank #55 · 29.2K reputationPosted Sep 3, 2014, 3:33 AM EDT
What error are you getting?
ghasem dehRank #8,160 · 227 reputationPosted Sep 3, 2014, 5:04 AM EDT