Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 9-Apr-11 1:18am
SIFNOk816
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
SAKryukov at 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 at 10-Apr-11 17:55pm
   
It might be overkill, but it's definitely a good reply - my 5
SAKryukov at 10-Apr-11 19:07pm
   
Well, come to think about, I agree, a 5.
--SA
SAKryukov at 10-Apr-11 23:50pm
   
5, after taking your note into account -- contradictory items.
(My answer is applicable anyway.)
--SA
SAKryukov at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v5
Comments
Espen Harlinn at 10-Apr-11 17:56pm
   
Nice and simple, my 5
SAKryukov at 10-Apr-11 19:07pm
   
Thank you, Espen.
--SA
d@nish at 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.
SAKryukov at 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
d@nish at 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.
SAKryukov at 11-Apr-11 0:19am
   
Not easy -- for just the 3D box? Well, it depends on the skills and understanding of geometry, but what's not about programming here? More degrees of freedom: +2 rotational. Cabinet or isometric projection is trivial, perspective projection need consideration of "camera" position. Some calculations to be done accurately, but certainly not programming issues...
 
Thank you.
--SA
d@nish at 11-Apr-11 0:23am
   
There are a lot of words in there which reminded me of Engineering Drawing I did in University. :)
d@nish at 11-Apr-11 1:40am
   
we missed something from the question. See my updated response if it makes any sense.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You might also like:
.NET Shape Control[^]
 
Regards
Espen Harlinn
  Permalink  
Comments
SAKryukov at 10-Apr-11 19:06pm
   
Another overkill :-) but a nice one -- a 5.
--SA
Espen Harlinn at 12-Apr-11 5:11am
   
Thanks SAKryukov!

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100