⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webcontrolsizeform.cs

📁 ASP.NET服务器控件高级编程电子书
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Web.UI.WebControls;

namespace WroxDesign.Design
{
	/// <summary>
	/// Summary description for WebControlSizeForm.
	/// </summary>
	public class WebControlSizeForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtWidth;
		private System.Windows.Forms.TextBox txtHeight;
		private System.Windows.Forms.GroupBox grpUnit;
		private System.Windows.Forms.Button btnAccept;
		private System.Windows.Forms.Button btnCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public WebControlSizeForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnCancel = new System.Windows.Forms.Button();
			this.grpUnit = new System.Windows.Forms.GroupBox();
			this.btnAccept = new System.Windows.Forms.Button();
			this.txtWidth = new System.Windows.Forms.TextBox();
			this.txtHeight = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// btnCancel
			// 
			this.btnCancel.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnCancel.Location = new System.Drawing.Point(84, 88);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(64, 24);
			this.btnCancel.TabIndex = 0;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// grpUnit
			// 
			this.grpUnit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.grpUnit.Location = new System.Drawing.Point(164, 4);
			this.grpUnit.Name = "grpUnit";
			this.grpUnit.Size = new System.Drawing.Size(136, 44);
			this.grpUnit.TabIndex = 3;
			this.grpUnit.TabStop = false;
			this.grpUnit.Text = "UnitType";
			// 
			// btnAccept
			// 
			this.btnAccept.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.btnAccept.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.btnAccept.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnAccept.Location = new System.Drawing.Point(12, 88);
			this.btnAccept.Name = "btnAccept";
			this.btnAccept.Size = new System.Drawing.Size(64, 24);
			this.btnAccept.TabIndex = 0;
			this.btnAccept.Text = "Accept";
			this.btnAccept.Click += new System.EventHandler(this.btnAccept_Click);
			// 
			// txtWidth
			// 
			this.txtWidth.Location = new System.Drawing.Point(64, 12);
			this.txtWidth.Name = "txtWidth";
			this.txtWidth.Size = new System.Drawing.Size(80, 21);
			this.txtWidth.TabIndex = 0;
			this.txtWidth.Text = "";
			// 
			// txtHeight
			// 
			this.txtHeight.Location = new System.Drawing.Point(64, 36);
			this.txtHeight.Name = "txtHeight";
			this.txtHeight.Size = new System.Drawing.Size(80, 21);
			this.txtHeight.TabIndex = 0;
			this.txtHeight.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Width:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 40);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "Heigth:";
			// 
			// WebControlSizeForm
			// 
			this.AcceptButton = this.btnAccept;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
			this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(153)), ((System.Byte)(153)), ((System.Byte)(255)));
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(310, 120);
			this.ControlBox = false;
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnCancel,
																		  this.btnAccept,
																		  this.grpUnit,
																		  this.txtHeight,
																		  this.txtWidth,
																		  this.label2,
																		  this.label1});
			this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "WebControlSizeForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Edit the WebControl Size";
			this.Load += new System.EventHandler(this.WebControlSizeForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private WebControlSize _size;

		private void WebControlSizeForm_Load(object sender, System.EventArgs e)
		{
			string[] values = Enum.GetNames(typeof(UnitType));

			int x = 10;		//Default left margin inside the group
			int y = 20;		//Default height of each option
			int sel = 0;	//The index of the selected option

			System.Windows.Forms.RadioButton btn;
			for (int i = 0; i < values.Length; i ++)
			{
				btn = new System.Windows.Forms.RadioButton();
				btn.Location = new Point(x, y * (i + 1));
				btn.Text = values[i];
				if (btn.Text == _size.Height.Type.ToString()) sel = i;
                grpUnit.Controls.Add(btn);
			}

			grpUnit.Height = y * values.Length + y * 2;
			this.Height = grpUnit.Height + 40;
			((System.Windows.Forms.RadioButton)grpUnit.Controls[sel]).Checked = true;
			
			txtHeight.Text = _size.Height.Value.ToString();
			txtWidth.Text = _size.Width.Value.ToString();
		}

		private void btnAccept_Click(object sender, System.EventArgs e)
		{
			try
			{
				System.Windows.Forms.RadioButton btn = null;
				foreach (System.Windows.Forms.RadioButton current in grpUnit.Controls)
					if (current.Checked) 
					{
						btn = current;
						break;
					}
                
				UnitType type = (UnitType)Enum.Parse(typeof(UnitType), btn.Text);
				Unit h = new Unit(int.Parse(txtHeight.Text), type);
				Unit w = new Unit(int.Parse(txtWidth.Text), type);
				_size = new WebControlSize(h, w);
				Close();
			}
			catch
			{
				throw new ArgumentException("The values are invalid!");
			}
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			Close();
		}

		internal WebControlSize CurrentSize
		{
			get { return _size; }
			set { _size = value; }
		}
	}
}

⌨️ 快捷键说明

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