在mdi子窗体之间画线 [英] Drawing Lines between mdi child forms

查看:71
本文介绍了在mdi子窗体之间画线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我正在使用Visual Studio 2005和C ++编写家谱应用程序,我想在mdi子窗体之间画线.
有人可以建议一个好的起点吗?如果有一些用C#编写的东西,那么我也许可以使用它,但是c ++会更可取.
目前,我有一些基本知识在工作-我创建了小的子表格-并分别进行显示.单击子窗体会在侧栏等上显示信息.
现在,我需要一些帮助来在子窗体之间绘制线条,以便在可能的情况下,当它们围绕线条移动时保持连接状态.

我是这里的新手,请保持温柔! :)

Mick White

Hi there
I''m writing a genealogy application using visual studio 2005 and C++ and I want to draw lines between mdi child forms.
Can anyone suggest a good place to start? If there''s something written in C# then I may be able to use that but c++ would be preferable.
I have the basics working at the moment - I create small child forms - and display them individually. Clicking on a child form displays information on a side bar etc.
I now need some help to draw lines between the child forms so that, if possible, when they''re moved around the lines stay attached.

I''m a newbie here so please be gentle! :)

Mick White

推荐答案

嗯,我不确定您的设计是否可行.您想为每个家庭使用子表格吗?还是每个人?考虑一下您最终将创建多少个子表单.

我认为您需要的是一个自定义控件,该控件模仿您孩子表单的行为.拥有"lil图形"功能的人应该随心所欲

只是我的2美分.
Hmmm, I''m not sure if you design is feasible. You want to use child form for each family? or each person? Think how many child forms you will end up creating.

I think what you need is a custom control that mimics the behaviors of your child form. That with ''lil graphics work you should be on your way

just my 2cents.


IMO,使用MDI和Child Forms会使自己的生活变得比原来更加艰难.

如果您的应用程序是标准"家谱类型,那么它与UML,类图或组织结构图应用程序非常相似,只是框"中包含的信息会有所不同.

可能我建议您搜索任何此类程序的开放源代码版本.例如 StarUML [ ^ ](那里的负载更多).

看看其中的一些,看看他们是如何做到的,并挑选对您来说最有意义的位.
IMO you are making life harder for yourself than it needs to be by using MDI and Child Forms.

If your application is the ''standard'' genealogy type then it is very similar to a UML, Class Diagram or Organization Chart application, just the information contained in the ''boxes'' will be different.

Might I suggest that you search for Open Source versions of any of that type of program. e.g. StarUML[^] (there are loads more out there).

Have a look at a few to see how they do it and pick the bits that make the most sense to you.


这种设计是一个非常常见的错误.从原则上讲,这甚至可能可行,但是我知道有很多尝试基于相似的想法(实际上好一点)来完成应用程序或组件,但都失败了.

有两种有效的方法.在这两种情况下,都不应将任何控件(甚至窗口或窗体)都用作图形元素.在您看来,它们似乎已经具有您需要的固有功能,但这是错误的.相反,它们具有的功能会让您迷失不必要的复杂性.

1)使用轻量级方法.在一个控件中创建所有图形基元.您需要在覆盖方法Control.OnPaintControl.Paint的处理程序中呈现所有图形.为了进行渲染,请使用事件参数参数中提供的System.Drawing.Graphics实例(在两种情况下).要更改图像,请使用Control.Invalidate.为了获得更好的性能,请将Control.Invalidate与参数(矩形"或区域")一起使用,以使场景的一部分无效.

2)使用WPF.您根本不需要进行任何渲染.相反,您应该使用Canvas并将图形基元(例如线条,矩形等,但您也可以将控件放置)放在画布上.这真的很简单.您甚至可以在矢量编辑器中绘制基元,将矢量图形作为XAML导入,将保存的XAML代码放入资源字典中,然后在画布上重复使用.我建议使用出色的开源编辑器InkScape.

最后的提示.在任何情况下都不能使用MDI.这是我的微软最失败的发明之一.即使Microsoft也不鼓励使用MDI.没有可靠的软件产品,甚至没有使用MDI可以接受的质量产品.如果使用它,您只会吓跑客户.最简单的替代方法是基于TabControl的选项卡式界面.

—SA
This design is a very common mistake. In principle, it may be even feasible, but I knew so many attempts to complete the application or component base on similar (actually a bit better) ideas — all failed.

There are two approaches which work. In both cases, you should not use any controls (not even windows or forms) as graphics elements. Maybe it seems to you they already have intrinsic functionality you need, but this is wrong. Just the opposite, they have functionality which will make you lost on unneeded complexity.

1) Use light-weight approach. Create all graphics primitive in one control. You need to render all graphics in the handler of Control.Paint of overridden method Control.OnPaint. For rendering, use the instance of System.Drawing.Graphics supplied in the event arguments parameter (in both cases). To change image, use Control.Invalidate. For better performance, use Control.Invalidate with a parameter (Rectangle or Region), to invalidate just a part of the scene.

2) Use WPF. You don''t need to do any rendering at all. Instead, you should use Canvas and put graphical primitives (such as lines, rectangles, etc., but you can put controls as well) on the canvas. This is really simple. You can even draw primitives in a vector editor, import vector graphics as XAML, put the saved XAML code to resource dictionary and reuse on your canvas. I recommend using wonderful Open Source editor InkScape.

Final note. There are no situations when MDI can be used. This is one of the most unsuccessful inventions my Microsoft. MDI is strongly discourages even by Microsoft. There are no solid software products or even products with acceptable quality using MDI. You would simply scare off your customers if you use it. The simplest nice alternative is tabbed interface, based on TabControl.

—SA


这篇关于在mdi子窗体之间画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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