datepickerdesigner.cs

来自「用C#编写的一个新的日期显示器」· CS 代码 · 共 71 行

CS
71
字号
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;

namespace Sorke.Web.UI.WebControls
{
	public class DatePickerDesigner : ControlDesigner
	{

		public override string GetDesignTimeHtml()
		{
			DatePicker datepicker = (DatePicker)base.Component;
			datepicker.Style.Add("position", "statis");
			Table table = new Table();
			table.BorderWidth = Unit.Pixel(0);
			table.CellPadding = 0;
			table.CellSpacing = 0;
			table.Width = datepicker.Width;
			table.Height = datepicker.Height;
			TableRow tableRow = new TableRow();
			TableCell tableCell1 = new TableCell();
			tableCell1.HorizontalAlign = HorizontalAlign.Center;
			tableCell1.VerticalAlign = VerticalAlign.Middle;
			TableCell tableCell2 = new TableCell();
			tableCell2.Width = Unit.Pixel(1);
			tableCell2.HorizontalAlign = HorizontalAlign.Center;
			tableCell2.VerticalAlign = VerticalAlign.Middle;
			TextBox textBox = new TextBox();
			textBox.ID = datepicker.ID;
			textBox.CssClass = datepicker.CssClass;
			textBox.Enabled = datepicker.Enabled;
			textBox.ToolTip = datepicker.ToolTip;
			textBox.Width = Unit.Percentage(100.0);
			textBox.Height = Unit.Percentage(100.0);
			textBox.Text = datepicker.Text;
			textBox.Attributes.Add("defaultValue", datepicker.Text);
			if (datepicker.ReadOnly)
			{
				textBox.ReadOnly = base.ReadOnly;
			}
			
			textBox.Style.Add("cursor", "hand");
			tableCell1.Controls.Add(textBox);
			Image image = new Image();
			/*if (datepicker.ImageUrl == "")
			{
				image.ImageUrl = "DatePicker.gif";
			}
			else
			{*/
				image.ImageUrl = datepicker.ImageUrl;
			//}
			image.BorderWidth = Unit.Pixel(0);
			image.Style.Add("cursor", "hand");
			tableCell2.Controls.Add(image);
			tableRow.Controls.Add(tableCell1);
			tableRow.Controls.Add(tableCell2);
			table.Controls.Add(tableRow);
			StringWriter stringWriter = new StringWriter();
			HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
			table.RenderControl(htmlTextWriter);
			return stringWriter.ToString();
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?