如何在 C# 中翻转/旋转标签Windows 窗体?
我将背景图像设置为我的标签。
在每个时间间隔,它都会向右侧移动三个像素。当它到达表格结束位置时,我需要将标签翻转并转回。
我尝试了以下方法,但没有得到解决方案。
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
,它可以将其文本旋转用户指定的任何角度。
extend label class& override paint method
您可以通过代码或简单地从工具箱中拖动来使用它。
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
财产。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)