C # Implementation text scrolls from left to right

Source: Internet
Author: User
Tags time interval

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;
 }
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.