[英]How can I flip/rotate the label in C#/Windows Forms?
如何在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
,它可以在用户指定的任何角度上旋转其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
属性即可根据需要更改角度。
所以......你可以这样做:
1.下载这个dll文件: http : //www.mediafire.com/download/hc16qezty0k6qnv/RotateLabel.dll
2.转到Visual Studio并打开解决方案
3.现在需要进入“项目”选项卡 - >添加引用... - >然后浏览下载的文件,只需添加该文件即可
4.下一步是右键单击ToolBox
5.完成后,您需要单击“选择项目”
6.浏览下载的文件并添加VerticalLabel
7.然后,您可以将VerticalLabel从“工具箱”拖动到表单。
就是这样,它很简单。
希望对你有所帮助我只是翻译了这个答案并使其变得更简单:)
祝你好运,Stralz
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.