ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

如何在C#/ Windows窗体中翻转/旋转标签?

2019-06-13 08:01:37  阅读:953  来源: 互联网

标签:c rotation image-rotation


如何在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,rotation,image-rotation
来源: https://codeday.me/bug/20190613/1231703.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有