Wednesday, April 29, 2015

How to perform rotation along with scaling for a text in GDI+

Hi,

I'm not sure, if I understand what you mean, but, when rotating objects in a given GraphicsContext at a specific point, you can use a GraphicsContainer.

I scaled everything by your scaling values and also used your hardcoded numbers...

            System.Drawing.Graphics formGraphics = this.CreateGraphics();        
            formGraphics.ScaleTransform(3f, 1);

            float width = formGraphics.MeasureString("Welcome", this.Font).Width;
            formGraphics.DrawRectangle(Pens.DarkRed, 72f, 92f, 237.25f, 151.3f);

            GraphicsContainer con = formGraphics.BeginContainer();

            Matrix mx = formGraphics.Transform; 
            mx.RotateAt(270, new PointF(72f, 92f), MatrixOrder.Append);
            mx.Translate(-83.5f, 0); 
            formGraphics.Transform = mx;
      
            string text = "Welcome";
            formGraphics.DrawString(text, this.Font, Brushes.OliveDrab, new RectangleF(83.5f, 94.99f, width, 13.44f));  

            formGraphics.EndContainer(con);

This will produce a stretched rectangle with a stretched vertical text in it

Regards,

  Thorsten.

No comments:

Post a Comment