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);
        }
发布了130 篇原创文章 · 获赞 20 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/yuxuac/article/details/101163968
今日推荐