效果如图:
点击右下角的数字可以让图片切换显示;
这个做起来不难,其实可以说是Flash编程了,首先要有一个Flash(.swf)文件。
下面是cs中的代码:
前台有一个服务器端控件Label;
下面的代码中红色部分是根据需要可以改动的;
private void CreateHtml()
{
string pics, links, texts;
{
string pics, links, texts;
pics = links = texts = "";
string quotes = @""""; //返回一个"符号
sql = "select top 4 title,filename from Source_MySource where userid='"+userid.ToString()+"' and reverse(left(reverse(filename),charindex('.',reverse(filename))-1))='gif' or reverse(left(reverse(filename),charindex('.',reverse(filename))-1))='jpg' order by sdate desc";
sql = "select top 4 title,filename from Source_MySource where userid='"+userid.ToString()+"' and reverse(left(reverse(filename),charindex('.',reverse(filename))-1))='gif' or reverse(left(reverse(filename),charindex('.',reverse(filename))-1))='jpg' order by sdate desc";
DataTable dt = DataAccess.GetDataTable(sql);
string[] imgUrl = new string[dt.Rows.Count];
string[] imgtext = new string[dt.Rows.Count];
string[] imgLink = new string[dt.Rows.Count];
string[] imgtext = new string[dt.Rows.Count];
string[] imgLink = new string[dt.Rows.Count];
if (dt.Rows.Count == 0)
{
Label1.Text = "";
{
Label1.Text = "";
return;
}
}
//开始字符串
string str = "<script type='text/javascript' language='javascript'>";
string str = "<script type='text/javascript' language='javascript'>";
for (int i = 0; i < dt.Rows.Count; i++)
{
imgUrl[i] = PubMethod.GetPath("35") + dt.Rows[i]["filename"].ToString();
str = str + "imgUrl" + i.ToString() + "='" + imgUrl[i].ToString() + "';";
{
imgUrl[i] = PubMethod.GetPath("35") + dt.Rows[i]["filename"].ToString();
str = str + "imgUrl" + i.ToString() + "='" + imgUrl[i].ToString() + "';";
imgtext[i] = dt.Rows[i]["title"].ToString();
str = str + "imgtext" + i.ToString() + "='" + imgtext[i].ToString() + "';";
str = str + "imgtext" + i.ToString() + "='" + imgtext[i].ToString() + "';";
imgLink[i] = "";
str = str + "imgLink" + i.ToString() + "='" + imgLink[i].ToString() + "';";
str = str + "imgLink" + i.ToString() + "='" + imgLink[i].ToString() + "';";
pics = pics + "+'|'+" + "imgUrl" + i.ToString();
links = links + "+'|'+" + "imgLink" + i.ToString();
texts = texts + "+'|'+" + "imgtext" + i.ToString();
}
str = str + "var focus_width=295;";
str = str + "var focus_height=230;";
str = str + "var text_height=20;";
str = str + "var swf_height = focus_height+text_height;";
str = str + "var focus_height=230;";
str = str + "var text_height=20;";
str = str + "var swf_height = focus_height+text_height;";
int pos = 0;
pos = pics.IndexOf("+'|'+");
pics = pics.Substring(pos + 5);
links = links.Substring(pos + 5);
texts = texts.Substring(pos + 5);
str = str + "var pics=" + pics + ";";
str = str + "var links=" + links + ";";
str = str + "var texts=" + texts + ";";
str = str + "var links=" + links + ";";
str = str + "var texts=" + texts + ";";
str = str + "document.write('<object classid=" + quotes + "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" + quotes + " codebase=" + quotes + "
http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" + quotes + " width=" + quotes + "'+ focus_width +'" + quotes + " height=" + quotes + "'+ swf_height +'" + quotes + ">');";
str = str + "document.write('<param name=" + quotes + "allowScriptAccess" + quotes + " value=" + quotes + "sameDomain" + quotes + "><param name=" + quotes + "movie" + quotes + " value=" + quotes + "../focus.swf" + quotes + "><param name=" + quotes + "quality" + quotes + " value=" + quotes + "high" + quotes + "><param name=" + quotes + "bgcolor" + quotes + " value=" + quotes + "#F0F0F0" + quotes + ">');";
str = str + "document.write('<param name=" + quotes + "menu" + quotes + " value=" + quotes + "false" + quotes + "><param name=wmode value=" + quotes + "opaque" + quotes + ">');";
str = str + "document.write('<param name=" + quotes + "FlashVars" + quotes + " value=" + quotes + "pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" + quotes + ">');";
str = str + "document.write('<embed src=" + quotes + "
focus.swf" + quotes + " wmode=" + quotes + "opaque" + quotes + " FlashVars=" + quotes + "pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" + quotes + " menu=" + quotes + "false" + quotes + " bgcolor=" + quotes + "#F0F0F0" + quotes + " quality=" + quotes + "high" + quotes + " width=" + quotes + "'+ focus_width +'" + quotes + " height=" + quotes + "'+ focus_height +'" + quotes + " allowScriptAccess=" + quotes + "sameDomain" + quotes + " type=" + quotes + "application/x-shockwave-flash" + quotes + " pluginspage=" + quotes + "
http://www.macromedia.com/go/getflashplayer" + quotes + " />');";
str = str + "document.write('</object>');";
str = str + "</script>";
Label1.Text = str;
}
}
我是把这个做成了一个控件,不过有一个问题始终没有弄明白:所使用的页面必须是控件路径的上一级,否则控件始终处于加载中,无法完成,很是怪异;