using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UserCtrlLib
{
public class RotateLabel:Label
{
public RotateLabel() {
this.AutoSize = false;
this.BackColor = Color.Transparent;
}
private float rotateAngle;
[Description("旋转角度")]
[Category("自定义外观")]
public float RotateAngle
{
get { return rotateAngle; }
set
{
rotateAngle = value;
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
float w = Width;
float h = Height;
//将graphics坐标原点移到矩形中心点
g.TranslateTransform(w / 2, h / 2);
g.RotateTransform(RotateAngle);
SizeF sz = g.MeasureString(Text, this.Font);
float x = -sz.Width / 2;
float y = -sz.Height / 2;
Brush brush = new SolidBrush(this.ForeColor);
g.DrawString(Text, this.Font, brush, new PointF(x, y));
}
}
}
文章来源地址https://www.toymoban.com/news/detail-726518.html
文章来源:https://www.toymoban.com/news/detail-726518.html
到了这里,关于Winform中实现会旋转的Label控件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!