如何在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窗体中翻转/旋转标签?


基础教程推荐
猜你喜欢
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- C#中的Linq to JSON操作详解 2023-06-08
- C# 解析XML和反序列化的示例 2023-04-14
- C#调用摄像头实现拍照功能的示例代码 2023-03-09
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- Unity shader实现高斯模糊效果 2023-01-16
- 实例详解C#实现http不同方法的请求 2022-12-26
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- C#中 Json 序列化去掉null值的方法 2022-11-18