In C #, text can be displayed through label controls, TextBox controls, forms, and PictureBox controls, and forms and PictureBox controls are implemented primarily through the DrawString method. TextBox controls and label controls are designed to display text information. To scroll through the text, you can combine the left and top properties of the label control with the timer control so that the label control moves once at a time, and if the time interval is appropriate, the text displayed in the label can be moved.
Example 27-01 text that scrolls from left to right
This example uses the Label control to scroll through the text. You can set the left property of a label control, such as "Label1," by scrolling to the right of the implementation text. left = Label1. Left + 50; ".
Run the program. Where the above text scrolls from left to right, the text below is scrolled from right to left, and the middle text is scrolled up and down.
Program Development Steps:
(1) Create a project named 27_01, and set the default form's Text property to "scrolling text."
(2) Add two Label controls on the form, a timer control, and set the timer control's Interval property to 200.
(3) The program code is as follows.
private void timer1_Tick(object sender, EventArgs e)
{
if (label1.Left < this.Width)
{
label1.Left = label1.Left + 50;
}
else if (label1.Left > -this.Width)
{
label1.Left = - label1.Width;
}
}