Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

You might also like:
.NET Shape Control[^]

Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 10-Apr-11 19:06pm    
Another overkill :-) but a nice one -- a 5.
--SA
Espen Harlinn 12-Apr-11 5:11am    
Thanks SAKryukov!
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.

[EDIT]
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
 
Share this answer
 
v5
Comments
Espen Harlinn 10-Apr-11 17:56pm    
Nice and simple, my 5
Sergey Alexandrovich Kryukov 10-Apr-11 19:07pm    
Thank you, Espen.
--SA
dan!sh 10-Apr-11 23:32pm    
OP probably needs a cube and not a rectangle. He has mentioned volumne in the post. I can think of two things, either his English is wrong or his maths is wrong. I went with former.
Sergey Alexandrovich Kryukov 10-Apr-11 23:51pm    
Thank you for this note. I'll add a reference to this note in my Answer -- it is valid in this case as well.
--SA
dan!sh 11-Apr-11 0:12am    
Of course it is. All one needs to do it use coordinate geometry wisely to create 3-D objects. But it surely is not going to be easy. He will have to find 8 co-ordinates based on LBH. If one uses Graphics class methods, drawing is very easy but the maths involved may put OP in trouble. Although it will be fun to write a library doing this.
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.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 10-Apr-11 17:18pm    
This article is overkill. Why 3D?
Please see my Answer -- this is a ready-to-use "article". :-)
--SA
Espen Harlinn 10-Apr-11 17:55pm    
It might be overkill, but it's definitely a good reply - my 5
Sergey Alexandrovich Kryukov 10-Apr-11 19:07pm    
Well, come to think about, I agree, a 5.
--SA
Sergey Alexandrovich Kryukov 10-Apr-11 23:50pm    
5, after taking your note into account -- contradictory items.
(My answer is applicable anyway.)
--SA
Sergey Alexandrovich Kryukov 11-Apr-11 1:52am    
@d@nish: I don't think we missed anything essential. All you say is correct, but the whole thing looks like a learning exercise. The whole idea of having a edit box for 3 components of the size tells it's nothing serious.

Should it be a really robust things with 3D navigation, it would be more in the class of advanced industrial design. I did such things, clearly understand the topic. This is where one could put forward real inventions with a very deep motivation of every detail (I mean UI and user experience, even the model of it.) It would be some special 3D control, something like in flight simulators, or much more complex or simple.

Let's just forget about it. What can be required in 3D box with arbitrary sizes, in fixed default orientation, automatically scaled to have the image filling the drawing area -- at best. That would be enough. End of story. If it's well beyond such a simple model -- it would go well beyond the Code Project format -- end of story again. Let's see what OP says...

--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900