Solved

How to apply RotateTransform to this control?

Posted on 2010-11-16
6
507 Views
Last Modified: 2013-12-17
The following control is very simple to draw when XY co-ordinates are in Top Left of the screen. But what if I want the control to rotate left or right. Please do understand that I would like to have the region set to the drawn portions, to clip any unwanted portions of the area.

Thank you Control to roate & set region
0
Comment
Question by:YetAnotherCoder
6 Comments
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
Is this for silverlight?

RotateTransform rt = new RotateTransform();

//rotate 90 clockwise
rt.Angle = 90;
//normal rotation is top left corner.  Setting to 0.5,0.5 rotates about the center.
rt.CenterX = 0.5;
rt.CenterY = 0.5;

myBmp.RenderTransform = rt;

Open in new window

0
 

Author Comment

by:YetAnotherCoder
Comment Utility
Hi ged325,

I am sorry for not making it clear. It is not for silverlight. It is a Windows User Control.
0
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
Unfortunately looks like you'll need WPF, which the above should apply for.  It doesn't look like it's possible in a normal windows application.

http://social.msdn.microsoft.com/Forums/en-SG/winforms/thread/38a6ecba-1b54-41c7-a3df-20670798c3df
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 32

Expert Comment

by:Erick37
Comment Utility
Give this a shot.

using System.Drawing.Drawing2D;
private void Form1_Paint(object sender, PaintEventArgs e)

		{

			Graphics g = e.Graphics;



			Pen pen = new Pen(Color.Black);



			g.RotateTransform(45.0f);  // rotate 45'

			g.TranslateTransform(this.ClientSize.Width / 2, this.ClientSize.Height  / 2, MatrixOrder.Append);           // translate



			g.DrawRectangle(pen,new Rectangle(-100, -40, 200, 80));

			g.DrawEllipse(pen, -100, -40, 200, 80);

		}

Open in new window

0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Add all the contents to a GraphicsPath, including an outer minimum bounding rectangle, and then use the Transform method to physically rotate all the points.  You can use a rotated GraphicsPath with just the outer minimum bounding rectangle to pass to the Region() constructor to clip the UserControl to the rotated image.

Again, this is the same stuff I've rehashed for you over and over again...  =\

Study this puppy again:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26541848.html#33921826
0
 

Author Comment

by:YetAnotherCoder
Comment Utility
Hi Eric,

Thanks for the reply. But what I have to do is this:

Quite similar to what you said but I have to set the region to the drawn area so that not drawn area will get clipped. So I have to do the following:

In addition to code of yours, I have to do this

Matrix M = new Matrix();
            // Translate the Origin to Center of the control in the matrix
            M.Translate(ClientRectangle.Width / 2, ClientRectangle.Height / 2);
            // If needs to be rotated then apply rotation as well for the above matrix
            if (SprayDirection == Spray_Direction.Left)
                M.RotateAt(90f, Center);
            else if (SprayDirection == Spray_Direction.Right)
                M.RotateAt(-90f, Center);
            // Re-compute all the graphics path points to the newly created matrix order
            gp.Transform(M);
            // Apply to the region
            Region rgn = new Region(gp);


0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now