效果如圖:
點擊右下角的數字可以讓圖片切換顯示;
這個做起來不難,其實可以說是Flash編程了,首先要有一個Flash(.swf)文件。
下面是cs中的代碼:
前臺有一個服務器端控件Label;
下面的代碼中紅色部分是根據需要可以改動的;
private void CreateHtml()
{
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";
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];
if (dt.Rows.Count == 0)
{
Label1.Text = "";
return;
}
//開始字符串
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() + "';";
imgtext[i] = dt.Rows[i]["title"].ToString();
str = str + "imgtext" + i.ToString() + "='" + imgtext[i].ToString() + "';";
imgLink[i] = "";
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;";
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 + "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;
}
我是把這個做成了一個控件,不過有一個問題始終沒有弄明白:所使用的頁面必須是控件路徑的上一級,否則控件始終處於加載中,無法完成,很是怪異;