在manged c ++中绘制可重复大小的形状 [英] Drawing re-sizable shapes in manged c++

查看:69
本文介绍了在manged c ++中绘制可重复大小的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





如何在VC ++表单中绘制可移动和可重新调整大小的形状(Line,Circle)。

解决方案

你必须使用一个控件对整个系统进行编程。它可以是一个自定义控件,或者说, Panel

形状这个词(不是形状)使它变得相当复杂事情。您需要开发类型层次结构,渲染,显示形状范围的所有图形元素,通过选择一个小矩形标记并移动它(或类似的东西)来更改形状。



但它的基础非常简单。您应该将所有图形数据放在某些数据模型中。您需要通过重写其方法 OnPaint 或处理其事件 Paint 来将此模型渲染到渲染控件上。您应该使用在这些方法的参数中传递给您的 System.Drawing.Graphics 的实例(这是初学者创建的常见错误绘制实例,在这种情况下会出错)。并且,要进行任何移动或转换,您需要使用 Control.Invalidate 来触发重绘。



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

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

mdi子表单之间的绘制线 [ ^ ]。



-SA

Hi,

How to draw movable and re-sizable shapes( Line, Circle) in VC++ forms.

解决方案

You have to program the whole system for doing so, using just one control. It could be a custom control, or, say, Panel.
The word "shapes" (not "shape") makes it a pretty complex thing. You would need to develop the type hierarchy, rendering, all those graphical elements showing the shape's extents, to change the shape by selecting a small rectangular marker and moving it (or something like that).

But the base of it is pretty simple. You should put all graphical data in some data model. You need to have rendering of this model onto the rendered control either by overriding its method OnPaint or handling its event Paint. You should use the instance of the System.Drawing.Graphics passed to you in these methods' parameter (it's a usual mistake of the beginners to create the Paint instance, which would be wrong in this case). And, to do any move or transformation, you need to use Control.Invalidate, to trigger the redrawing.

Please see my past answers for further detail:
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
Drawing Lines between mdi child forms[^].

—SA


这篇关于在manged c ++中绘制可重复大小的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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