📄 webcustomcontrol1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MapOut
{
public class WebCustomControl1 : WebControl
{
private string strSrc;
public string Src
{
get
{
return strSrc;
}
set
{
strSrc = value;
}
}
protected override void CreateChildControls()
{
HttpContext.Current.Response.Write("<style>");
HttpContext.Current.Response.Write(".drag{position:relative;cursor:pointer}");
HttpContext.Current.Response.Write("body {");
HttpContext.Current.Response.Write("background-color: #000000;");
HttpContext.Current.Response.Write("}");
HttpContext.Current.Response.Write("</style>");
HttpContext.Current.Response.Write("<script type=" + "\"" + "text/javascript" + "\"" + " language=" + "\"" + "JavaScript1.2" + "\"" + " >\n");
HttpContext.Current.Response.Write("var dragapproved=false;\n");
HttpContext.Current.Response.Write("var z,x,y;\n");
HttpContext.Current.Response.Write("function move()\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("if(event.button==1&&dragapproved)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("z.style.pixelLeft=temp1+event.clientX-x;\n");
HttpContext.Current.Response.Write("z.style.pixelTop=temp2+event.clientY-y;\n");
HttpContext.Current.Response.Write("return false;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("function drags()\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("if(!document.all)\n");
HttpContext.Current.Response.Write("return;\n");
HttpContext.Current.Response.Write("if(event.srcElement.className==" + "\"" + "drag" + "\"" + ")");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("dragapproved=true;\n");
HttpContext.Current.Response.Write("z=event.srcElement;\n");
HttpContext.Current.Response.Write("temp1=z.style.pixelLeft;\n");
HttpContext.Current.Response.Write("temp2=z.style.pixelTop;\n");
HttpContext.Current.Response.Write("x=event.clientX;\n");
HttpContext.Current.Response.Write("y=event.clientY;\n");
HttpContext.Current.Response.Write("document.onmousemove=move;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("document.onmousedown=drags;\n");
HttpContext.Current.Response.Write("document.onmouseup=function()\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("dragapproved=false;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("function resizeimg(ImgD,iwidth,iheight)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("var image=new Image();\n");
HttpContext.Current.Response.Write("image.src=ImgD.src;\n");
HttpContext.Current.Response.Write("if(image.width>0 && image.height>0)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("if(image.width/image.height>= iwidth/iheight)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("if(image.width>iwidth)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("ImgD.width=iwidth;\n");
HttpContext.Current.Response.Write("ImgD.height=(image.height*iwidth)/image.width;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("else\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("ImgD.width=image.width;\n");
HttpContext.Current.Response.Write("ImgD.height=image.height;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("ImgD.alt = image.width +" + "\"" + "×" + "\"" + "+ image.height;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("else\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("if(image.height>iheight)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("ImgD.height=iheight;\n");
HttpContext.Current.Response.Write("ImgD.width = (image.width * iheight) / image.height;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("else\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("ImgD.width=image.width;\n");
HttpContext.Current.Response.Write("ImgD.height=image.height;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("ImgD.alt=image.width+" + "\"" +"×" + "\"" + "+image.height;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("ImgD.style.cursor=" + "\"" + "pointer" + "\"" + ";\n");
HttpContext.Current.Response.Write("if (navigator.userAgent.toLowerCase().indexOf(" + "\"" + "ie" + "\"" + ") > -1)\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("ImgD.title =" + "\"" + "请使用鼠标滚轮缩放图片,点击图片可在新窗口打开" + "\"" + ";\n");
HttpContext.Current.Response.Write("ImgD.onmousewheel = function img_zoom()\n");
HttpContext.Current.Response.Write("{");
HttpContext.Current.Response.Write("var zoom = parseInt(this.style.zoom, 10) || 100;\n");
HttpContext.Current.Response.Write("zoom += event.wheelDelta / 12;\n");
HttpContext.Current.Response.Write("if (zoom> 0) this.style.zoom = zoom +" + "\"" + "%" + "\"" + ";\n");
HttpContext.Current.Response.Write("return false;\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("else\n");
HttpContext.Current.Response.Write("{\n");
HttpContext.Current.Response.Write("ImgD.title =" + "\"" + "点击图片可在新窗口打开" + "\"" + ";\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("}\n");
HttpContext.Current.Response.Write("</script>\n");
//HttpContext.Current.Response.Write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'/>");
//HttpContext.Current.Response.Write("</head>");
//HttpContext.Current.Response.Write("<body>");
this.Controls.Add(new LiteralControl("<img src=" + "\"" + Src + "\"" + " height=" + "\"" + "200 " + "\"" + " width=" + "\"" + "400" + "\"" + " class=" + "\"" + "drag" + "\"" + " alt=" + "\"" + "点击拖动它" + "\"" + " onload=" + "\"" + "resizeimg(this,100,200)" + "\"" + "/>"));
//HttpContext.Current.Response.Write("</body>");
//HttpContext.Current.Response.Write("</html>");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -