WinForm实现仿视频播放器左下角滚动新闻效果的方法

时间:2021-12-01 07:58:47

本文实例讲述了WinForm实现仿视频播放器左下角滚动新闻效果的方法。分享给大家供大家参考。具体实现方法如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using System.Xml.Linq;
namespace App
{
 public partial class Form7 : Form
 {
  private int Index { get; set; }
  private DataTable dataTable { get; set; }
  private System.Timers.Timer timer { get; set; }
  public Form7()
  {
   InitializeComponent();
   dataTable = new DataTable();
   dataTable.Columns.AddRange(new DataColumn[] {
    new DataColumn("Id",typeof(System.Int32)),
    new DataColumn("DisplayName",typeof(System.String)),
    new DataColumn("URL",typeof(System.String))
   });
   DataRow row = dataTable.NewRow();
   row["Id"] = 1;
   row["DisplayName"] = "百度百科欢迎你!";
   row["URL"] = "http://www.baidu.com";
   dataTable.Rows.Add(row);
   row = dataTable.NewRow();
   row["Id"] = 2;
   row["DisplayName"] = "刘XX明星已经现身搜狐网站,赶快去围观!";
   row["URL"] = "http://www.sohu.com";
   dataTable.Rows.Add(row);
   row = dataTable.NewRow();
   row["Id"] = 3;
   row["DisplayName"] = "新浪新闻出现重大新闻,点我快速查看!";
   row["URL"] = "http://www.sina.com.cn";
   dataTable.Rows.Add(row);
   row = dataTable.NewRow();
   row["Id"] = 4;
   row["DisplayName"] = "网易客户端出现新版本啦,赶快去体验把!";
   row["URL"] = "http://www.126.com";
   dataTable.Rows.Add(row);
   label1.Text = lblContent.Top.ToString();
   timer = new System.Timers.Timer(2000);
   timer.Elapsed += delegate
   {
    CharsMouse();
   };
   timer.Start();
   button1.Click += delegate
   {
    CharsMouse();
   };
   button2.Click += delegate
   {
    timer.Dispose();
   };
   lblContent.LinkClicked += delegate
   {
    label2.Text = dataTable.Rows[Index]["URL"].ToString();
   };
  }
  void CharsMouse()
  {
   this.lblContent.Invoke(new MethodInvoker(delegate
   {
    if (Index >= dataTable.Rows.Count)
     Index = 0;
    while (lblContent.Top > -lblContent.Height)
    {
     lblContent.Top = lblContent.Top - 2;
     label1.Text = "1.Top=" + lblContent.Top.ToString();
     System.Threading.Thread.Sleep(100);
     Application.DoEvents();
    }
    lblContent.Text = dataTable.Rows[Index]["DisplayName"].ToString();
    lblContent.Top = 2;
    timer.Enabled = false;
    Application.DoEvents();
    System.Threading.Thread.Sleep(2000);
    timer.Enabled = true;
    Index++;
   }));
  }
 }
}

希望本文所述对大家的C#程序设计有所帮助。