从文本框值绘制矩形(LxWxH) [英] Draw Rectangle (LxWxH) from textbox value

查看:98
本文介绍了从文本框值绘制矩形(LxWxH)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想知道是否有人可以显示我或将我指向正确的方向,以便能够从表单或图片框上的文本框值中绘制一个具有长度x宽度x高度的矢量矩形.

干杯

Hi All

I was wondering if someone could show me or point me in the right direction to be able to draw a vector rectangle with Lenght x Width x Height from text box value on a form or picturebox.

Cheers

推荐答案

您可以使用GDI +执行此操作.还有 [
You can use GDI+ for doing this. There is also this[^] nice article on CP which might help you.

Update: Looks like we all missed the point. Assuming you need to draw a cube or a cuboid, length, breadth and height are not enough. This will never tell you the intended orientation of the object in the space. If that is all the information you have, you will end up drawing your perception of object in space. I hope I am clear. To get the real position in the space of the object, you will need at least some co-ordinates if not all. To me it is not enough input to draw the object. You can very well draw the isometric view and then let the user rotate the object. This, surely, will need you to handle the axis about which the rotation is done and also provide a smooth flicker-free movement. I am sure there are libraries available that ca help you do this. So you might be better off using a readily available component rather tht doing yourself. Although it''s your call.

Another thing that I noticed is use of "vector". Are you referring that those three input numbers will be the vector values in i, j and k axis and then you need to draw a projection of that? This is totally different from drawing a rectangle. This will involve you drawing upto 4 triangles who share sides with each other. This again will be easier to do using the already available libraries than doing yourself. Your call again.


在某些控件(甚至表单)中的被覆盖的System.Windows.Forms.Control.OnPaint中绘制矩形,或事件Paint的处理程序.帮自己一个忙,不要使用任何图像控件,直接在控件上绘制.在事件参数中使用为您提供的System.Drawing.Graphics实例(在两种情况下).帮自己一个忙-不要为控件创建Graphics实例:已经为您提供了该实例(创建此实例是一个非常常见的错误).

矩形的参数取决于一些数据,例如位置和大小.将这些参数设置为表单控件的字段.根据文本框中的文本之一更新其值:将其Text解析为整数(或浮点)值.为此使用string.Splitinteger.Parse或float.Parse.数据字段更新后,请使用Control.Invalidate-此方法将触发在渲染矩形(以及其他任何位置)的控件的重新渲染.

这就是您可能需要的全部.


在d @ nish指出暗示的图像可能是一个盒子而不是矩形之后:确定,但是在这种情况下,我的答案也是有效的:多次使用Graphics.DrawLine(而不是DrawRectangle)来组成您需要的图像.

—SA
Draw rectangle in some Control (even a form) in overridden System.Windows.Forms.Control.OnPaint, or a handler of the event Paint. Do yourself a favor, do not use any image control, draw directly on a control. Use the instance of System.Drawing.Graphics provided for you in event arguments (in both cases). Do yourself another favor — do not create the instance of Graphics for the control: it''s already provided for you (creating this instance is a very common mistake).

The parameters of the rectangle depends on some data, such as position and size. Make those parameters the fields of your control of form. Update their values based one the text from the text box: parse its Text into integer (or float) values. Use string.Split and integer.Parse or float.Parse for this purpose. As soon as the data fields are updated, use Control.Invalidate — this method will trigger re-rendering of the control where you render you rectangle (and whatever else).

That''s all you may possibly need.


After d@nish noted that implied image might be a box, not rectangle: sure, but in this case my Answer is valid too: use Graphics.DrawLine several times (instead of DrawRectangle) to compose the image you need.

—SA


您可能还会喜欢:
.NET形状控制 [
You might also like:
.NET Shape Control[^]

Regards
Espen Harlinn


这篇关于从文本框值绘制矩形(LxWxH)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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