How can I flip/rotate the label in C#/Windows Forms?

断了今生、忘了曾经 提交于 2021-02-16 13:09:27

问题


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

回答1:


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.

You have to set the below properties.

newlbl.Text = "";           
newlbl.AutoSize = false;      
newlbl.NewText = "ravindra";     
newlbl.ForeColor = Color.Green;  
newlbl.RotateAngle = -90; 

Change angle as required by simply changing the RotateAngle property.




回答2:


So...You can do this way:

1.Download this dll file : http://www.mediafire.com/download/hc16qezty0k6qnv/RotateLabel.dll

2.Go on your Visual Studio and open your solution

3.Now you need to go on Projects tab -> Add references... -> Then browse the file you downloaded and simply add that file

4.Next step is to right click on ToolBox

5.After you done that you need to click on Choose Items

6.Again browse your downloaded file and add VerticalLabel

7.Then you can drag VerticalLabel from the Toolbox to your form.

That is it, its simple.

Hope that helped you i just translated this answer and made it simpler :)

Good luck, Stralz



来源:https://stackoverflow.com/questions/12601774/how-can-i-flip-rotate-the-label-in-c-windows-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!