c# - 文字 中心 旋轉

        public static void DrawRotatedTextAt(Graphics gr, float angle, string txt, float x, float y, Font the_font, Brush the_brush)
        {
            // Text rectangle
            var fontRect = gr.MeasureString(txt, the_font);

            // Save the graphics state.
            GraphicsState state = gr.Save();
            gr.ResetTransform();

            // Rotate.
            gr.RotateTransform(angle);

            // Translate to desired position. Be sure to append the rotation so it occurs after the rotation.
            gr.TranslateTransform(x + fontRect.Width / 2, y + fontRect.Height / 2, MatrixOrder.Append);

            // Draw
            gr.DrawString(txt, the_font, the_brush, -fontRect.Width / 2, -fontRect.Height / 2);
            //gr.DrawRectangle(new Pen(the_brush, 1), -fontRect.Width / 2, -fontRect.Height / 2, fontRect.Width, fontRect.Height);

            // Restore the graphics state.
            gr.Restore(state);
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章