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

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

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#程序设计有所帮助。

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。