滚动文字

 

滚动字幕案例:

屏幕宽度:Screen.PrimaryScreen.Bounds.Width

屏幕高度:Screen.PrimaryScreen.Bounds.height

滚动条:scrollbars.none(不显示)

Textbox.textlength与Textbox.selectionLength的区别:

前者是所有文字的长度;后者是选中文字的长度

 

 

 

类:是对象的抽象化,也是由属性,方法,事件组成

不能直接使用。如果需要使用,必须将这个类实例化;

实例化的本质就是将这个类转换成一个新的对象;

 

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

namespace 滚动字幕案例
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
            SoundPlayer sound = new SoundPlayer();
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Size = new Size(400,400);
            this.Location = new Point(Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2);
            this.BackColor = Color.Black;
            textBox1.Width = this.Width;
            textBox1.Location = new Point(0, 0);
            textBox1.TextAlign = HorizontalAlignment.Center;
            textBox1.Font = new Font("楷体", 18);
            textBox1.ForeColor = Color.White;
            textBox1.BackColor = Color.Black;
            textBox1.SelectionStart = textBox1.TextLength;
            textBox1.Top = this.Height;
            sound.SoundLocation = "shengpizi.wav";
            sound.PlayLooping();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Top = textBox1.Top - 2;
            if (textBox1.Top <=-textBox1.Height) 
            {
                textBox1.Top = this.Height;
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_43437202/article/details/85254998