1

I would like to make the text scrolling upwards or downloads.

In html we can use Marquees "Cool Effects with Marquees!" , sample2 The c# WebBrowser control doesn't recognize the syntax of Marquees

One way in c# is to use listbox, then rolling the listbox using timer.

I am wondering if there is an easy way to do it.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
camino
  • 10,085
  • 20
  • 64
  • 115
  • 1
    I guess your best bet is to use a label and set the Location within a loop or timer. – Abdullah Leghari Jan 19 '19 at 21:57
  • 1
    If you want to draw animated text on a control, you need to create a custom control, having a timer, then move the text location in the timer and invalidate the control. Override its paint and render the text in new location. – Reza Aghaei Jan 19 '19 at 22:03
  • 1
    Or [something like this](https://stackoverflow.com/a/53990288/7444103), controlling (multiplying) the measure of the text string. – Jimi Jan 19 '19 at 22:05

1 Answers1

1

If you want to draw animated text on a control, you need to create a custom control, having a timer, then move the text location in the timer and invalidate the control. Override its paint and render the text in new location.

You can find a Left to Right and Right to Left Marquee Label in my other answer here: Right to Left and Left to Right Marquee Label in Windows Forms.

Windows Forms Marquee Label - Vertical

In the following example, I've created a MarqueeLabel control which animates the text vertically:

using System;
using System.Drawing;
using System.Windows.Forms;
public class MarqueeLabel : Label
{
    Timer timer;
    public MarqueeLabel()
    {
        DoubleBuffered = true;
        timer = new Timer();
        timer.Interval = 100;
        timer.Enabled = true;
        timer.Tick += Timer_Tick;
    }
    int? top;
    int textHeight = 0;
    private void Timer_Tick(object sender, EventArgs e)
    {
        top -= 3;
        if (top < -textHeight)
            top = Height;
        Invalidate();
    }
    protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.Clear(BackColor);
        var s = TextRenderer.MeasureText(Text, Font, new Size(Width, 0),
            TextFormatFlags.TextBoxControl | TextFormatFlags.WordBreak);
        textHeight = s.Height;
        if (!top.HasValue) top = Height;
        TextRenderer.DrawText(e.Graphics, Text, Font,
            new Rectangle(0, top.Value, Width, textHeight),
            ForeColor, BackColor, TextFormatFlags.TextBoxControl |
            TextFormatFlags.WordBreak);
    }
    protected override void Dispose(bool disposing)
    {
        if (disposing)
            timer.Dispose();
        base.Dispose(disposing);
    }
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398