使用鼠标控件在图片框中平移和缩放图像 [英] Panning and zooming image within a picturebox using mouse controls

查看:85
本文介绍了使用鼠标控件在图片框中平移和缩放图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表单上,我有一个包含图像的图片框。但是,此图像对于盒子本身来说太大了。我需要一种方法,我可以单击并拖动以平移图像,并使用滚轮进行放大和缩小。我搜索过很多帖子,但找不到直接有效的方法。这就是我现在所处的位置:



我决定制作一个我的图片框所在的面板,并将autoscroll设置为true。这样我就可以直接拖动图片框了。但是,我甚至不确定如何做到这一点。稍微思考一点,我知道我需要点击鼠标的位置(在图片框上),然后在鼠标释放事件之后移动图片框与移动鼠标的像素数相同,但我该如何做这个?我不确定完成这项工作所需的语法。至于放大和缩小,我肯定会迷路。



所有帮助都很感激。然而回复告诉我看看另一篇文章并不符合我的利益,因为我花了几个小时这样做,看起来好像我看了每一个可能的页面。



谢谢。

On my form, I have a picture box that contains an image. This image, however, is too large for the box itself. I need a way where I can click and drag to pan the image, and use the scroll wheel to zoom in and out. I have searched through many posts but could not find a direct and efficient way of doing this. This is where I am right now:

I decided to make a panel where my picture box would be located, and set the autoscroll to true. This way I could just drag the picture box itself around. But, I am unsure of even how to do that. Thinking a bit I know I need to take the position of my mouse on click (on the picture box) and then move the picture box the same amount of pixels that I moved the mouse, after the mouse release event but how do I do all this? I am unsure of the syntax required to do this job. As for the zooming in and out, I am lost for sure.

All help appreciated. However replying to tell me to take a look at another article is not in my interest since I spent the past few hours doing so and it would seem as if I looked at every possible page.

Thank you.

推荐答案

解决方案很简单:停止滥用 PictireBox 。这个简单的控件类可以帮助你在最简单​​的情况下,而不是在这里帮助你,与使用从<$ c $派生的自定义控件类相比,只会创建不需要的中间层来消耗额外的资源并浪费额外的开发时间而不会产生任何回报c> System.Windows.Forms.Control 。



请参阅我过去的答案以获取更多详细信息:

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ],

在图片框中附加图片 [ ^ ]。



参见:

在mdi子表单之间绘制线条[ ^ ],
捕捉面板上的图纸 [ ^ ],

什么样的有趣的方法是油漆? (DataGridViewImageCell.Paint(...)) [ ^ ]。



-SA
The solution is simple: stop abusing PictireBox. This simple control class which could help you in simplest cases, not helping you here, only creates unwanted intermediate layer to eat up extra resources and waste extra development time giving nothing in return, compared to using a custom control class derived from System.Windows.Forms.Control.

Please see my past answers for further detail:
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(...))[^].

—SA


另一个解决方案是:

将您的自定义控件设为SA建议。如果您没有时间,请访问Google并搜索免费成像sdk。



你可以找到几个免费的成像SDK,包括ThumbnailViewer,ImageViewer和DocumentViewer。这很方便。

您还可以在图片框中找到平移和放大镜(MagnifyingGlass)类。
Another solution is:
Make your custom control as SA suggested. If you do not have time to do it, please go to Google and search for "free imaging sdk".

You can find several free imaging SDKs including ThumbnailViewer, ImageViewer and DocumentViewer. This is convinient.
You can also find classes of "Panning" and "Magnifier (MagnifyingGlass)" for picture box.


我做了一些狩猎一个简单的解决方案,并遇到了这个解决方案,所以我想与你分享。这应该可以解决您的问题,这是一个非常简单的实现。



我希望这会有所帮助。



一个简单的平移图片框 [ ^ ]
I did a little hunting around for a simple solution for you and came across this solution so I wanted to share it with you. This should solve your problem and it is a pretty easy implementation.

I hope this helps.

A Simple Panning PictureBox[^]


这篇关于使用鼠标控件在图片框中平移和缩放图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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