C#图片查看器无法专注于 [英] C# picture viewer can not focus on

查看:145
本文介绍了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


这篇关于C#图片查看器无法专注于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆