Moi Moi

Moi Moi

  • 2.1k
  • 7
  • 328

Multiple Text rotation

Apr 1 2022 8:57 PM

Hi,

I need to draw 3 string around a circle , a string every 120°.

My first problem is  : There is a rotation (0 to 360°) of the string around the circle.

My second problem is : All the text needs to be horizontal to be easily readable.

I've made a function to draw a single text and it works but I don't find the tips to make it working with 3 text.

        private void DrawText(Graphics myGraphics,int AngularPosition,string StrTmp, Font FntVerin,float VerticalTranslation)
        {
            myGraphics.TranslateTransform(0, -VerticalTranslation);
            myGraphics.RotateTransform(-Rotation);
            SizeF stringSize = new SizeF();
            int stringWidth = 100;
            // Set string format.
            StringFormat newStringFormat = new StringFormat();
            newStringFormat.FormatFlags = StringFormatFlags.DirectionVertical;

            stringSize = myGraphics.MeasureString(StrTmp, FntVerin, stringWidth, newStringFormat);

            Point PtCircle = new Point();
            PtCircle.X = (int)(Math.Cos(Rotation / 360.0 * Math.PI));
            PtCircle.Y = (int)(Math.Sin(Rotation / 360.0 * Math.PI));
            float DeltaX = 0.0f;
            if (Rotation < 90) { DeltaX = (float)(Math.Sin(Rotation / 360.0 * Math.PI) + (stringSize.Height / 2)); }
            else if (Rotation < 180) { DeltaX = (float)(Math.Sin((180.0 - Rotation) / 360.0 * Math.PI) + (stringSize.Height / 2)); }
            else if (Rotation < 270) { DeltaX = (float)(Math.Sin((Rotation - 180.0) / 360.0 * Math.PI) - (stringSize.Height / 2)); }
            else if (Rotation < 360) { DeltaX = (float)(Math.Sin((180.0 - (Rotation - 180.0)) / 360.0 * Math.PI) - (stringSize.Height / 2)); }
            //myGraphics.DrawRectangle(new Pen(Color.Red, 1), PtCircle.X - stringSize.Height/2 + DeltaX, PtCircle.Y - stringSize.Width/2, stringSize.Height, stringSize.Width);            
            myGraphics.DrawString(StrTmp, FntVerin, Brushes.Blue, PtCircle.X - stringSize.Height / 2 + DeltaX, PtCircle.Y - stringSize.Width / 2);
            //myGraphics.DrawString("+", font1, Brushes.Blue, -11, )-10);

            myGraphics.TranslateTransform(0, VerticalTranslation);
        }

I call the function in the Paint of my panel

Thanks for your help

 

 


Answers (1)