This article describes the implementation method of C# scrolling subtitles and is shared with you for your reference. The specific methods are as follows:
In C#, the implementation of scrolling the screen is actually very simple, and only methods are required. (String s, Font font, Brush brush, PointF point) Draw the specified text string at the specified position and use the specified Brush and Font objects.
Parameter description:
s The string to be drawn.
font It defines the text format of a string.
brush It determines the color and texture of the drawn text.
point structure, which specifies the upper left corner of the drawn text.
Among them, what we want to use is the point function, which controls the offset of the text by controlling its X or Y parameters. The following is a horizontal scrolling subtitles as an example.
public string text="csdn baihe_591";
private void FrmShow_Load(object sender, EventArgs e)
{
= new Point(149, 13);
= new Size(134, 16);
(label);
= "";
this. = true;
this. = 500;
p = new PointF(, 0);
}
PointF p;
Font f = new Font("Song style", 10);
Color c = ;
string temp;
private void timer1_Tick(object sender, EventArgs e)
{
Graphics g = ();
SizeF s = new SizeF();
s = (text, f);//Measure text length
Brush brush = ;
(c);//Clear the background
if (temp != text)// When the text changes, redisplay
{
p = new PointF(, 0);
temp = text;
}
else
p = new PointF( - 10, 0);//One offset 10 each time
if ( <= -)
p = new PointF(, 0);
(text, f, brush, p);
}
I hope this article will be helpful to everyone's C# programming.