如何在C#/ Windows窗体中翻转/旋转标签?
作者:互联网
如何在C#Windows Forms中翻转/旋转标签?
我将背景图像设置为我的标签.
在每个时间间隔,它将三个像素移动到右侧.当它到达表格结束位置时,我需要翻转并转回标签.
我尝试了以下方式,但我没有得到解决方案.
private void timer1_Tick(object sender, EventArgs e){
if (label2.Location.X < this.Width)
label2.Location = new Point(label2.Location.X + incr, label2.Location.Y);
else
{
incr = -2;
label2.Location = new Point(label2.Location.X - 50, label2.Location.Y);
label1.Image.RotateFlip();
}
this.Refresh();
}
解决方法:
创建一个类newlabel,它可以在用户指定的任何角度上旋转其Text.
extend label class& override paint method
您可以通过代码使用它或只是从ToolBox拖动.
using System.Drawing;
class newLabel : System.Windows.Forms.Label
{
public int RotateAngle { get; set; }
public string NewText { get; set; }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Brush b =new SolidBrush(this.ForeColor);
e.Graphics.TranslateTransform(this.Width / 2, this.Height / 2);
e.Graphics.RotateTransform(this.RotateAngle);
e.Graphics.DrawString(this.NewText, this.Font,b , 0f, 0f);
base.OnPaint(e);
}
}
现在拖动此自定义控件以用于表单.
您必须设置以下属性.
newlbl.Text = "";
newlbl.AutoSize = false;
newlbl.NewText = "ravindra";
newlbl.ForeColor = Color.Green;
newlbl.RotateAngle = -90;
只需更改RotateAngle属性即可根据需要更改角度.
标签:c,rotation,image-rotation 来源: https://codeday.me/bug/20190613/1231703.html