简体   繁体   English

如何平移和缩放窗体

[英]How to Pan and Zoom on a Form

So, I have been using this code to display an image for an application I am working on. 因此,我一直在使用此代码显示我正在处理的应用程序的图像。

e.Graphics.DrawImage(global::Map.Properties.Resources.bigmap, 0, 0, 980, 980);

Which in turn gives me this. 这反过来给了我这个。 (Edit: New guys can't post images. Sorry. You can however view it here- Map ) (编辑:新手无法发布图片。对不起。不过,您可以在此处查看它- 地图

Which is nice and all but considering the resolution is around 3500X3500 I would like to be able to zoom and pan it. 不错,但考虑到分辨率约为3500X3500,我希望能够缩放和平移它。 So, is there a way for me to do this? 那么,我有办法吗?

I faced this problem this very week. 这一周我遇到了这个问题。

Try something like this . 试试这样 It worked well for me. 对我来说效果很好。

Quick and dirty method? 快速又肮脏的方法? Save the image to an external file and open it in a WebBrowser control. 将图像保存到外部文件,然后在WebBrowser控件中将其打开。 Provides built-in panning and zooming. 提供内置的平移和缩放。 Otherwise, you'll need to capture mouse movements, scroll wheel handlers, etc... All of which can be done, but is much more work. 否则,您将需要捕获鼠标的移动,滚轮处理程序等。所有这些都可以完成,但要做的工作还很多。 To save the image, from what I can tell from your code, just: 要保存图像,根据我的代码可以告诉我的只是:

Map.Properties.Resources.bigmap.Save(System.Environment.CurrentLocation + "\\temp.bmp");
MapWebBrowser.Navigate(System.Environment.CurrentLocation + "\\temp.bmp");

Apologies if the code doesn't work out of the box, but it should be a good starting point. 如果代码不能立即使用,则表示歉意,但这应该是一个很好的起点。 I don't have a copy of C# with me right now. 我现在没有C#的副本。 Let me know if you need more explanation. 让我知道是否需要更多说明。 (MapWebBrowser needs to be added, its just a WebBrowserControl). (需要添加MapWebBrowser,它只是一个WebBrowserControl)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM