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

📄 textbox.cs

📁 一种.net实现ajax方法的类库
💻 CS
字号:
/** Copyright (c) 2006, All-In-One Creations, Ltd.*  All rights reserved.* * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:* *     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.*     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.*     * Neither the name of All-In-One Creations, Ltd. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**//**
 * Project: emergetk: stateful web framework for the masses
 * File name: .cs
 * Description:
 *   
 * Author: Ben Joldersma
 *   
 * @see The GNU Public License (GPL)
 */
/* 
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 2 of the License, or 
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along 
 * with this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
using System;
using EmergeTk.Model;
using System.ComponentModel;

namespace EmergeTk.Widgets.Html
{
	public delegate void WidgetChangedHandler( Widget sender, object newValue );
	/// <summary>
	/// Summary description for TextBox.
	/// </summary>
    [DefaultProperty("Text")]
	public class TextBox : Widget, IDataBindable
	{
        private class mytest : ILocatable
        {

            #region ILocatable Members

            public System.Drawing.Point Point
            {
                get
                {
                    throw new Exception("The method or operation is not implemented.");
                }
                set
                {
                    throw new Exception("The method or operation is not implemented.");
                }
            }

            #endregion
        }
		//isPassword, isDisabled, rows, cols
		private const string UpdateFormat = "{0}.SetText('{1}');";

        private bool isPassword = false, isDisabled = false, isRich = false, isCodeView=false;
		private int rows = 1, cols = 0;
		private string text, currentTextOnClient;

		public string Text
		{
			get
			{
				return text;
			}
			set
			{
                if (text != value  && value != null)
                {
                    text = value;
                    if (this.rendered && text != currentTextOnClient)
                        InvokeClientMethod("SetText", Util.ToJavaScriptString(value));
                    currentTextOnClient = text;
                    ClientArguments["defaultValue"] = Util.Quotize(Util.FormatForClient(value));
                    RaisePropertyChangedNotification("Text");
                }                
			}
		}

        public bool IsRich { get { return isRich; } set { isRich = value; ClientArguments["isRich"] = isRich ? "1" : "0"; } }
        public bool IsDisabled { get { return isDisabled; } set { isDisabled = value; ClientArguments["isDisabled"] = isDisabled ? "1" : "0"; } }
        public bool IsPassword { get { return isPassword; } set { isPassword = value; ClientArguments["isPassword"] = isPassword ? "1" : "0"; } }
        public bool IsCodeView { get { return isCodeView; } set { isCodeView = value; ClientArguments["isCodeView"] = isCodeView ? "1" : "0"; } }
        public int Rows { get { return rows; } set { rows = value; ClientArguments["rows"] = rows.ToString(); } }
        public int Columns { get { return cols; } set { cols = value; ClientArguments["cols"] = cols.ToString(); } }

		public void Changed( string newText )
		{
			if( newText.StartsWith("!") )
			{
				int count = int.Parse( newText.Substring(1) );
				newText = Model.AbstractRecord.GetWords(count);
				Text = newText;
			}

            currentTextOnClient = newText;
			Text = newText;

			if( OnChanged != null )
			{
				OnChanged( this, newText );
			}
            if (onKeyUp != null)
            {
                onKeyUp(this, newText);
            }
		}

        public event WidgetChangedHandler OnChanged;

        private event OnClickHandler onKeyUp;
        public event OnClickHandler OnKeyUp
        {
            add { onKeyUp += value; ClientArguments["onKeyUp"] = "1"; }
            remove { onKeyUp -= value; }
        }

		public TextBox( string id, string text )
		{
			this.id = id;
			this.text = text;
		}

        public override void Init()
        {
            //ClientArguments["defaultValue"] = "''";
        }

		public TextBox(){}

		public override void HandleEvents(string evt, string args)
		{
			if( evt == "OnChanged" )
			{
				Changed( args );
			}
            else
            {
                base.HandleEvents(evt, args);
            }
		}

		public override string ToString()
		{
			return Text;
		}

        override public object Value
        {
            get
            {
                return this.Text;
            }
            set
            {
                if( value != null )
                    Changed(value.ToString());
                RaisePropertyChangedNotification("Value");
            }
        }

        public bool IsPassThrough
        {
            get { return false; }
        }

        override public string DefaultProperty
        {
            get { return "Text"; }
        }

        private Binding binding;
        public Binding Binding
        {
            get { return binding; }
            set { binding = value; }
        }

	}
}

⌨️ 快捷键说明

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