📄 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;
using System.Security.Permissions;
namespace MyLabel
{
[
AspNetHostingPermission(SecurityAction.Demand,Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand,Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1 runat=\"server\"> </{0}:WebCustomControl1>")
]
public class WebCustomControl1 : WebControl
{
public string textName;
public int intMax;
[
Bindable(true),
Category("Appearance"),
DefaultValue(""),
Description("显示文本!"),
Localizable(true)
]
public virtual string Text
{
get
{
string s = (string)ViewState["textName"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["textName"] = value;
}
}
[
Bindable(true),
Category("Appearance"),
DefaultValue(""),
Description("设置当前日期!"),
Localizable(true)
]
public virtual int intYear
{
get
{
return intMax;
}
set
{
intMax = value;
}
}
protected override void RenderContents(HtmlTextWriter writer)
{
if ((Text != "")&&(intYear.ToString() != ""&& intYear > 1990))
{
writer.Write("<h2>" + Text +":"+ intYear.ToString()+ "</h2>");
}
else
{
writer.Write("<h2>" + "默认年份:" + DateTime.Now.Year.ToString() + "</h2>");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -