【问题标题】:How can I flip/rotate the label in C#/Windows Forms?如何在 C#/Windows 窗体中翻转/旋转标签?
【发布时间】:2012-09-26 12:31:07
【问题描述】:

如何在 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();
}

【问题讨论】:

标签: c# rotation image-rotation


【解决方案1】:

创建一个类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 属性即可根据需要更改角度。

【讨论】:

  • 如果标签尺寸太小,比如 28x82,文本会在文本区域的右上角生成。有没有办法确保在左下角生成文本。这是 -90 度角。
【解决方案2】:

所以...你可以这样做:

1.下载这个dll文件:http://www.mediafire.com/download/hc16qezty0k6qnv/RotateLabel.dll

2.在 Visual Studio 上打开解决方案

3.现在你需要进入项目选项卡 -> 添加引用... -> 然后浏览 您下载的文件,只需添加该文件

4.下一步是右键单击工具箱

5.完成后,您需要点击选择项目

6.再次浏览您下载的文件并添加 VerticalLabel

7.然后您可以将VerticalLabel从工具箱拖到您的表单中。

就是这样,很简单。

希望对您有所帮助,我刚刚翻译了这个 answer 并使其更简单:)

祝你好运, 斯特拉尔兹

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-11
    • 2010-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多