How can I flip/rotate the label in C#/Windows Forms?(如何在 C#/Windows 窗体中翻转/旋转标签?)
问题描述
如何在 C# Windows 窗体中翻转/旋转标签?
How can I flip/rotate the label in C# Windows Forms?
我将背景图片设置为我的标签.
I set the background image to my label.
在每个时间间隔,它都会向右移动三个像素.当它到达表单结束位置时,我需要将标签翻转并返回.
At every time interval it moves three pixels to the right side. When it reaches the form end position I need the label to be flipped and turned back.
我尝试了以下方法,但没有得到解决方案.
I have tried the following way, but I didn't get the solution.
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.
Create a class, newlabel
, which can rotate its Text on any angle specified by the user.
extend label class& override paint method
您可以通过代码使用它,也可以简单地从工具箱中拖动它.
You can use it by code or simply dragging from the 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);
}
}
现在将要使用的自定义控件拖到表单中.
Now drag this custom control to be used into your form.
您必须设置以下属性.
newlbl.Text = "";
newlbl.AutoSize = false;
newlbl.NewText = "ravindra";
newlbl.ForeColor = Color.Green;
newlbl.RotateAngle = -90;
只需更改 RotateAngle
属性即可根据需要更改角度.
Change angle as required by simply changing the RotateAngle
property.
这篇关于如何在 C#/Windows 窗体中翻转/旋转标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C#/Windows 窗体中翻转/旋转标签?


- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01