如何在C#Windows Forms中翻转/旋转标签?我将背景图像设置为我的标签.在每个时间间隔,它将三个像素移动到右侧.当它到达表格结束位置时,我需要翻转并转回标签.我尝试了以下方式,但我没有得到解决方案.private void...
如何在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#/ Windows窗体中翻转/旋转标签?
猜你喜欢
- user32.dll 函数说明小结 2022-12-26
- Unity3D实现渐变颜色效果 2023-01-16
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- .NET CORE DI 依赖注入 2023-09-27
- Unity Shader实现模糊效果 2023-04-27
- c# 模拟线性回归的示例 2023-03-14
- 如何使用C# 捕获进程输出 2023-03-10
- Oracle中for循环的使用方法 2023-07-04