C#图片查看器无法专注于

问题描述:

我用C#4.0编写了一个图片查看器.当鼠标滚轮滚动时,我希望图片能够缩小并集中在鼠标点上.然后,我在窗口窗体"中拖动一个PictureBox,并添加mouseWheel事件,但是当我转动鼠标时,Vscroll栏会移动,同时PictureBox会缩小和增长.有没有人知道该如何减少鼠标滚轮时动作的方法(Vscroll bar用鼠标滚轮移动)?谢谢.

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.

焦点"始终表示键盘焦点",仅此而已.您需要使控件具有针对性.请参阅:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.canfocus.aspx [ ^ ].

您不应出于目的使用PictureBox.更确切地说,原则上这是可能的,但完全没有意义.我在过去的回答中对此进行了解释.请参阅:
如何从旧图纸中清除面板 [ ^ ],
在C#中绘制矩形 [在图片框内添加图片 [在mdi子表单之间画线 [在面板上捕获图形 [ Paint是一种哪种好玩的方法? (DataGridViewImageCell.Paint(...)) [ http://msdn.microsoft.com/en-us/library/system. windows.forms.scrollablecontrol.aspx [ ^ ].

您需要以像素为单位计算场景的整个区域",并将其分配给属性 AutoScrollMinSize,控件使用该属性确定在每个方向上滚动多少.属性AutoScroll应该为true.有关更多详细信息,请参见此类的其他"AutoScroll…"成员.

—SA
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