draw diagonal ellipse

10-17-2006, 10:58 AM
I need to draw an oval on my windows form but it has to be slanted (for instance, the top coordinates should be something like 100,100 and the bottom could be 300,300). The regular DrawEllipse method can't work for that. I'm trying the DrawCurve but can't seem to get it. Can someone please tell me how to do it?

10-17-2006, 03:45 PM
I would recommend doing a quick GDI rotation transform to make a "diagonal" ellipse.
Rotate the Graphics object, draw the ellipse normally and then unrotate (reset). To draw somewhere besides in the upper left, use a Translation transform as well. :)

10-17-2006, 03:57 PM
Okay I'll give it a shot. You don't have any sample code do you? I know how to move an ellipse using that Translate function, but not how to skew it.

EDIT: Nevermind. I just put the RotateTransform function in and it works. Thanks very very much!!!!!!

10-17-2006, 05:07 PM
Hi. I'm having real issues positioning the new ellipse, the one that is skewed. I don't quite understand how the position works once the graphics is transformed. Like say if I rotate 90 degrees, how do I position that ellipse over top of the other one in its middle (so it looks kinda like a cross)? Can you explain?

10-17-2006, 05:32 PM
Positioning things:

Find the location where you would like to draw the center of the object on the form (CeX, CeY).
Use TranslateTransform to move the new zero position to this point on the forum (only applicable the first time, as it is all relative positioning):
.TranslateTransform(CeX, CeY)

RotateTransform so it's in the direction you want.

Draw the ellipse so that its center is at 0, 0
For example, if you want the width of the ellipse to be 100 and the height to be 50, you'd draw the ellipse with Left of -50 and Top of -25 ... with the same size, the center will be at 0, 0 - and 0, 0 is now corresponding to point (CeX, CeY) on the form.
Use .ResetTransform to return back to normal. :)

10-18-2006, 10:09 AM
I can't get it to work. I want the ellipse to be in the middle of the form so I set CeX to Form.width/2 and CeY to Form.height/2. I do the transform, rotate by 90 degrees and then draw an ellipse (-width/2, -height/2, width, height). That gives me the bottom right part of the ellipse in the top left corner of the form. If I don't divide the size by 2, I get the entire ellipse positioned in the top left corner.

10-18-2006, 10:19 AM
Nevermind :p There was an extra line of code in there that was throwing off the translation :-\ . It works now. Thanks very much Iceplug.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum