Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am using c# and creating some line drawings. I want to create a rectangle or possibly rounded rectangle drawing but with a rotation applied to it.

Im declaring using:

C#
System.Windows.Rect rect = new System.Windows.Rect(startpos.X, startpos.Y, halfsize*2, halfsize * 4);


I now need to rotate this flat rectangle by say, 30 degrees and THEN draw it.

How do I do this?

I am using the drawing context object to render.

Thanks in advance!
Posted
Updated 31-Aug-13 12:37pm
v3
Comments
mccaber82 30-Aug-13 8:30am    
Just to elaborate this is C# .net v4.5
Sergey Alexandrovich Kryukov 30-Aug-13 10:57am    
You rather need to tag the UI library or application type you are using. And your "THEN" is irrelevant — just think about it...
—SA
mccaber82 30-Aug-13 11:03am    
Thank you for that unbelievably insightful comment. Perhaps you could be helpful enough to explain how to update tags after the question has been posted??
Sergey Alexandrovich Kryukov 30-Aug-13 11:41am    
With pleasure: click at Improve question.
Please understand that is can be critical to get help, because if the library is uncertain, many people would not post solution for different ones, as such solutions can be very different.

But at this moment I see you already got a solution. Great.

—SA

Try some of these links[^].
 
Share this answer
 
Ok, worked it out thanks to Richard's steer. Here's the code:

// Rectangle to draw.
System.Windows.Rect rect = new System.Windows.Rect(startpos.X, startpos.Y, width, height);
           
// Set rotation on drawing context.
drawingContext.PushTransform(new Media.RotateTransform(angle, ratio.X, ratio.Y));
            
// Draw our rectangle.
drawingContext.DrawRectangle(null, myPen, rect);

// Remove transformation for rotation as its no longer needed.
drawingContext.Pop();
 
Share this answer
 

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