WinForm实现仿视频播放器左下角滚动新闻效果的方法
本文实例讲述了WinForm实现仿视频播放器左下角滚动新闻效果的方法。分享给大家供大家参考。具体实现方法如下:
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; usingSystem.Drawing.Imaging; usingSystem.IO; usingSystem.Xml.Linq; namespaceApp { publicpartialclassForm7:Form { privateintIndex{get;set;} privateDataTabledataTable{get;set;} privateSystem.Timers.Timertimer{get;set;} publicForm7() { InitializeComponent(); dataTable=newDataTable(); dataTable.Columns.AddRange(newDataColumn[]{ newDataColumn("Id",typeof(System.Int32)), newDataColumn("DisplayName",typeof(System.String)), newDataColumn("URL",typeof(System.String)) }); DataRowrow=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=newSystem.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(); }; } voidCharsMouse() { this.lblContent.Invoke(newMethodInvoker(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#程序设计有所帮助。