第一步:
在.cs文件中加一个引用:using System.IO;
public string strNews;
private void Page_Load(object sender, System.EventArgs e)
{
//读取new.text文件,并把内容给strNews用与滚动显示
FileStream fs = new FileStream("c://通知.txt", FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
strNews = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);
strNews=strNews.Replace("/r","<br>");
strNews=strNews.Replace("/0"," ");
strNews=strNews.Replace("/t"," ");
strNews=strNews.Replace(" "," ");
}
第二步:在html下<body>区域加一个MARQUEE :
<MARQUEE onmouseover=this.stop() style="BORDER-RIGHT: dimgray thin; BORDER-TOP: dimgray thin solid; Z-INDEX: 101; LEFT: 8px; BORDER-LEFT: dimgray thin; WIDTH: 780px; COLOR: green; BORDER-BOTTOM: dimgray thin solid; POSITION: absolute; TOP: 358px; HEIGHT: 57px; TEXT-DECORATION: none" onmouseout=this.start() scrollAmount=3 scrollDelay=80 direction=up><%=strNews%></MARQUEE>
在.cs文件中加一个引用:using System.IO;
public string strNews;
private void Page_Load(object sender, System.EventArgs e)
{
//读取new.text文件,并把内容给strNews用与滚动显示
FileStream fs = new FileStream("c://通知.txt", FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
strNews = System.Text.Encoding.GetEncoding("gb2312").GetString(bytes);
strNews=strNews.Replace("/r","<br>");
strNews=strNews.Replace("/0"," ");
strNews=strNews.Replace("/t"," ");
strNews=strNews.Replace(" "," ");
}
第二步:在html下<body>区域加一个MARQUEE :
<MARQUEE onmouseover=this.stop() style="BORDER-RIGHT: dimgray thin; BORDER-TOP: dimgray thin solid; Z-INDEX: 101; LEFT: 8px; BORDER-LEFT: dimgray thin; WIDTH: 780px; COLOR: green; BORDER-BOTTOM: dimgray thin solid; POSITION: absolute; TOP: 358px; HEIGHT: 57px; TEXT-DECORATION: none" onmouseout=this.start() scrollAmount=3 scrollDelay=80 direction=up><%=strNews%></MARQUEE>
本文介绍了一种在网页上从本地文本文件读取内容并使用滚动条进行展示的方法。通过C#后端处理读取文件,再利用HTML的MARQUEE标签实现文本滚动显示效果。

被折叠的 条评论
为什么被折叠?



