Winform 如何在界面控件上加上一行旋转角度的字体内容

来源:互联网 发布:淘宝运营教程百度云 编辑:程序博客网 时间:2024/05/17 01:17
  1. private void DrawStringAndRotateAt(System.Windows.Forms.Panel panel,string strChar)  
  2.       {  
  3.           //以(100,100)为中心画字符串并旋转   
  4.               Graphics g = panel.CreateGraphics(); //需要在上面写字的控件  
  5.           Font font = new Font("Impact ", 30);//字体名称大小  
  6.          PointF rotatePoint = new PointF(this.panel1.Height / 2, this.panel1.Width / 2); //设定旋转的中心点  
  7.           SizeF size = g.MeasureString(strChar, font);  
  8.           Matrix myMatrix = new Matrix();  
  9.           myMatrix.RotateAt(270, rotatePoint, MatrixOrder.Append); //旋转270度  
  10.           g.Transform = myMatrix;  
  11.           g.DrawString(str, font, new SolidBrush(Color.Black), rotatePoint.X - size.Width, rotatePoint.Y - size.Height); //写字  
  12.          }  

阅读全文
0 0