C# 实现窗口界面里字体旋转

 主要的核心代码:

public  class PublicFunction
    {
        public static PublicFunction _publicFunc =new PublicFunction();

        public static PublicFunction CreateInstance()
        {
            return _publicFunc;
        }
        public PublicFunction()
        {          
        }
        public void RotateFont(PaintEventArgs e,String strChar,Panel ppanel,float angle,Font ffont,Color ccolor)
        {
            Graphics g = e.Graphics; //需要在上面写字的控件

            float w = ppanel.Width;
            float h = ppanel.Height;            //将graphics坐标原点移到矩形中心点            
            g.TranslateTransform(w / 2, h / 2);
            g.RotateTransform(angle);
            SizeF sz = g.MeasureString(strChar, ffont);
            float x = -sz.Width / 2;
            float y = -sz.Height / 2;
            Brush brush = new SolidBrush(ccolor);
            g.DrawString(strChar, ffont, brush, new PointF(x, y));
        }
    }

调用实例:

        private void panelAmplitude_Paint(object sender, PaintEventArgs e)
        {
            _strChar = "Amplitude/dB";
            PublicFunction.CreateInstance().RotateFont(e, _strChar, panelAmplitude, _angle, label1.Font, this.ForeColor);
        }

发布了147 篇原创文章 · 获赞 146 · 访问量 77万+

猜你喜欢

转载自blog.csdn.net/miao0967020148/article/details/98347480
今日推荐