C# 中的交互式绘图

发布于 2024-12-17 15:27:42 字数 693 浏览 2 评论 0原文

我需要在 C# WinForms 中绘制一个大型的交互式树结构 - 公司层次结构。

除了在树中排列块的算法可能会非常复杂之外,我不太确定如何实现实际的画布和绘图代码。

乍一看,我可以创建一个巨大的图像(或较大图像的矩阵),并使用 GraphicsBufferedGraphics 来渲染给定用户缩放位置的小区域进入。这将产生您可能在 Google 地图上看到的缩放和平移效果。

至于交互性,这里可以做什么?我希望用户能够突出显示某些人(特定成本中心的人、承包商等)。此外,如果随着用户放大,树逐渐显示更多有关员工的信息,那就太酷了。我是否应该使用 MouseMove 事件进行命中测试,并以编程方式添加/删除/更改构成画布上图片的内容?

我应该避免使用 GDI 而应该使用 DirectDraw 来代替吗?我不想太过分 - 我只是希望能够直观地表示结构并为用户提供打印它的选项。

或者,是否有一个(免费软件?)库可以允许通过交互进行缩放和平移?我可能问得有点多,但也许也可以处理树结构?

我对较小规模的每个单独概念都有经验,但没有任何东西可以像这样的大型结构结合在一起。我预测,如果我做错了什么,它可能会变得非常缓慢、滞后和占用内存。

我只涉足过WPF。我几乎只在 .Net 中使用 WinForms - WPF 中是否有某些东西可以使这项任务变得更加容易?

I need to draw a large, interactive tree structure in C# WinForms - a corporate hierarchy.

Aside from the algorithm which will arrange the blocks in the tree which is probably going to be quite complex, I'm not really sure about how to go about implementing the actual canvas and drawing code.

At first glance, I could create a giant Image (or a matrix of largeish images), and use a Graphics or BufferedGraphics to render a small region given where the user is zoomed into. This would give the zooming and panning effect you might see on Google Maps.

As for interactivity, what can be done here? I'd like the user to be able to highlight certain people (people in a particular cost centre, people who are contractors, etc...). Also, it would be pretty cool if the tree showed progressively more information about the staff as the user is zoomed in more. Should I just be doing hit testing with the MouseMove event and programatically add/remove/alter the things which make up the picture on the canvas?

Is this something that I should avoid using GDI for and maybe using DirectDraw instead? I don't want to go overkill - I just want to be able to visually represent the structure and give users the option to print it.

Alternatively, is there a (freeware?) library available which allows zooming and panning with interactivity? I might be asking a bit much, but maybe one which also can handle tree structures?

I have experience with each individual concept on a smaller scale, however nothing brought together in a largeish structure like this. I predict that if I do something wrong, it can turn into something very slow, laggy, and memory-hogging.

I've only dabbled in WPF. I almost exclusively use WinForms in .Net - is there something in WPF which would make this task significantly easier?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聊慰 2024-12-24 15:27:42

我不知道这是否是一个答案,但我使用 GDI+ 做了很多交互式图形工作,我觉得我可以用它非常有效地工作。无论是树结构还是您所描述的树结构,以及多功能布局编辑器和浏览照片等。

想要的是将所有内容绘制在大位图上。避免使用大位图。 :-)

因此,要么使用框架提供的双缓冲图形,要么自己设计。但是,如果您想远程运行应用程序,这可能并不完美: http://blogs.msdn.com/b/oldnewthing/archive/2006/01/03/508694.aspx

基本上你只是把你想要的一切绘制一个列表,并使用它在屏幕上结束位置的信息更新它,以便您可以在 OnMouseDown/OnMouseMove/OnMouseUp 中对其进行点击测试。您很快就会注意到需要保留一个枚举来表示交互所处的状态(例如 DraggingObject、MakingSelection、Scrolling 等)和 Point _lastMousePosition。

逻辑非常简单。使其不闪烁并具有响应能力可能并不那么简单。

I don't know if this even is an answer, but I do a lot of interactive graphical work using GDI+ and I feel that I can work very effectivly with it. Both when it comes to tree structures exacly as the one you describe as well as versatile layout editors and over to browsing photos etc.

What you do not want is painting everything on a large bitmap. Avoid large bitmaps. :-)

So either you use double buffered graphics as provided by the framework or you design it on you own. This may not be perfect if you want to run your app remotely, however: http://blogs.msdn.com/b/oldnewthing/archive/2006/01/03/508694.aspx

Basically you just put everything you want to draw in a list and update it with inforamtion on exactly where it ended you on screen so that you can hit-test for it in OnMouseDown/OnMouseMove/OnMouseUp. You'll soon notice the need for keeping an enum for which state the interaction is in (eg.g DraggingObject, MakingSelection, Scrolling etc) and a Point _lastMousePosition.

The logic is pretty simple. Making it flicker-free and responsive may not be that simple.

梦途 2024-12-24 15:27:42

假设您继续使用 WinForms,一种选择是为每个需要公开交互的项目创建您自己的自定义控件。

然后创建另一个自定义控件来容纳它们和主画布。给它一个画布(例如面板)和几个滚动条。

当使用滚动条时,根据需要动态创建和删除子控件。超过一定的缩放级别,您可能需要从控件切换到直接绘制的非交互式图像。

该模型假设用户不会同时与多个控件进行交互。如果你提供一个套索让他们选择多个项目,事情就会很快变得困难。

Assuming that you are staying with WinForms, one option would be to create your own custom control for each item that needs to expose interactions.

Then create another custom control that will house them and the master canvas. Give it a canvas (e.g. Panel) and a couple of scroll bars.

When the scroll bars are used, dynamically create and remove the child controls as needed. Beyond a certain zoom level you may need to switch from controls to directly drawn, non-interactive images.

This model assumes that users won't be interacting with more than one control at a time. If you offer a lasso that lets them select multiple items things get hard fast.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文