Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I write a picture viewer in C#4.0. When mouse wheel scrolls, I want the picture to be able to shrink and grow focus on the mouse point. Then I drag a PictureBox in window Form, and add mouseWheel event, but when I wheel my mouse, the Vscroll bar moved, the same time the PictureBox shrinks and grows. Does any one know the method how to reduce the action(Vscroll bar moved with mouse wheel),when wheel my mouse? Thank you.
Posted

1 solution

The "focus" always means "keyboard focus" and nothing else. You need to make your control focusable. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.canfocus.aspx[^].

You should not use PictureBox for your purpose. More exactly, in principle, this is possible, but totally pointless. I explained it in my past answers. Please see:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

See also:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

In addition to the techniques explained in my answers referenced above, you can organize scrolling in a very simple way. You can use the class already designed for this purpose: System.Windows.Forms.ScrollableControl:
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.aspx[^].

You need to calculate the "whole area" of the scene in pixels and assign it to the property AutoScrollMinSize, which is used by the control to determine how much to scroll in each direction. The property AutoScroll should be true. Please see other "AutoScroll…" members of this class for further detail.

—SA
 
Share this answer
 
v2
Comments
bubifengyun 23-Oct-12 9:51am    
Thanks for your suggestion. I am trying another's code, which works very well and is panel not picturebox. I quit my code.
Sergey Alexandrovich Kryukov 23-Oct-12 14:14pm    
Sure.
Good luck, call again.
--SA

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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