复合控件之Anthem
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
namespace CustomComponents
{
/// <summary>
/// Summary description for newcontrol.
/// </summary>
public class newcontrol : WebControl, INamingContainer
{
// public event EventHandler Change;
private static readonly object EventCheck = new object();
private static readonly object EventCancel = new object();
Anthem.TextBox box;
Anthem.Button addButton;
Anthem.Button subtractButton;
System.Web.UI.WebControls.Label title;
public string Title
{
get
{
this.EnsureChildControls();
return ((System.Web.UI.WebControls.Label)Controls[2]).Text;
}
set
{
this.EnsureChildControls();
((System.Web.UI.WebControls.Label)Controls[2]).Text = value.ToString();
}
}
public int Value
{
get
{
this.EnsureChildControls();
return Int32.Parse(((Anthem.TextBox)Controls[4]).Text);
}
set
{
this.EnsureChildControls();
((Anthem.TextBox)Controls[4]).Text = value.ToString();
}
}
[
Bindable(true),
Category("Behavior"),
DefaultValue(""),
Description("The text to display on the box height")
]
public virtual string heightvalue
{
get
{
string s = (string)ViewState["heightvalue"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["heightvalue"] = value;
}
}
protected void OnCheck(EventArgs e)
{
EventHandler checkHandler = (EventHandler)Events[EventCheck];
if (checkHandler != null)
{
checkHandler(this, e);
}
}
protected void OnCancel(EventArgs e)
{
EventHandler cancelHandler = (EventHandler)Events[EventCancel];
if (cancelHandler != null)
{
cancelHandler(this, e);
}
}
#region Events
[
Category("Action"),
Description("Raised when the user clicks the check button")
]
public event EventHandler Check
{
add
{
Events.AddHandler(EventCheck, value);
}
remove
{
Events.RemoveHandler(EventCheck, value);
}
}
[
Category("Action"),
Description("Raised when the user clicks the cancel button")
]
public event EventHandler Cancel
{
add
{
Events.AddHandler(EventCancel, value);
}
remove
{
Events.RemoveHandler(EventCancel, value);
}
}
#endregion
protected override void CreateChildControls()
{
this.Controls.Add(new LiteralControl("<div id='sb_divall' style='position:absolute;top:0;background:#777;FILTER: alpha(opacity=60);opacity:0.6;left:0;Z-INDEX: 10001;width:100%;height:"+heightvalue+"'></div>"));
this.Controls.Add(new LiteralControl("<div id='sb_divfull' align='center' style='Z-INDEX: 10002;border:1px solid #ffff99; LEFT: 328px; WIDTH: 513px; POSITION: absolute; TOP: 112px; HEIGHT: 208px;BACKGROUND-COLOR: #777'>"));
title=new System.Web.UI.WebControls.Label();
title.Text="Title";
title.Width=System.Web.UI.WebControls.Unit.Percentage(100);
title.Height=System.Web.UI.WebControls.Unit.Pixel(10);
title.BackColor=System.Drawing.Color.FromName("#777");
this.Controls.Add(title);
this.Controls.Add(new LiteralControl("<br>"));
box = new Anthem.TextBox();
box.Text = "0";
box.TextMode=System.Web.UI.WebControls.TextBoxMode.MultiLine;
box.AutoUpdateAfterCallBack=true;
box.Width=System.Web.UI.WebControls.Unit.Percentage(100);
box.Height=System.Web.UI.WebControls.Unit.Percentage(80);
this.Controls.Add(box);
this.Controls.Add(new LiteralControl("<br>"));
addButton = new Anthem.Button();
addButton.Text = "确定";
addButton.Click += new EventHandler(this.AddBtn_Click);
addButton.AutoUpdateAfterCallBack=true;
this.Controls.Add(addButton);
this.Controls.Add(new LiteralControl(" "));
subtractButton = new Anthem.Button();
subtractButton.Text = "取消";
subtractButton.AutoUpdateAfterCallBack=true;
subtractButton.Click += new EventHandler(this.SubtractBtn_Click);
this.Controls.Add(subtractButton);
this.Controls.Add(new LiteralControl("</div>"));
}
private void AddBtn_Click(Object sender, EventArgs e)
{
OnCheck(e);
}
private void SubtractBtn_Click(Object sender, EventArgs e)
{
OnCancel(e);
}
}
}