winform滚动字幕

最近因项目需要,需在winform中实现文字从右向左,从下向上,滚动效果,其中试过在PictureBox,RichTexBox,Label组件中实现文字滚动,发现Label中效果最好,PictureBox次之,RichTexBox中不能实现。



现分享如下:Label控件中实现从下向上滚动效果,PictureBox组件中实现从右向左滚动效果,winform工程中添加Label,PictureBox组件,各创建一个Label,PictureBox的继承类,实现如下:

Label继承类:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace gundong
{
    class NewLabel : Label
    {
        public NewLabel()
        {

            this.updateTimer = new Timer();
            this.updateTimer.Interval = 30;
            this.updateTimer.Enabled = true;
            this.updateTimer.Tick += delegate { this.OnTick(); };
            //drawRect.X = x;
            drawRect.X = this.width + stringSize.Width;
            drawRect.Y = y;
            drawRect.Width = width;
            //drawRect.Height = height;
            drawRect.Height = GetHeight();
            //x = 0 - stringSize.Width;
            //x = this.width + stringSize.Width;
        }

        private Timer updateTimer;
        String drawString = "文字很长时,就会超出这个矩形框,我想实现的功能是。我给你看看。。尽量不要在重绘的时候赋图片。重绘一般都画图神马的。。程序写好了不会导致闪烁的。状态栏走马灯似的移动文本,重绘代码发上来。我给你看看。";
        Font drawFont = new Font("宋体", 12);
        SizeF stringSize = new SizeF();
        SolidBrush drawBrush = new SolidBrush(Color.Black);
        float x = 0;
        float y = 200;
        //float width = 562;
        float width = 283;
        float height = 90;
       
        RectangleF drawRect = new RectangleF();
        //从左到右
        // pri

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值