问题大概是这样。 我重写一个TextBox 控件 增加两个属性 。1,一個屬性表示TextBox 綁定的Class name;
2,一個屬性表示 TextBox 绑定Class 的 属性名称想在设计器 里 实现如下效果 当输入1 属性时 2,属性列出该类型的所有属性(下拉选项)用户选一个并赋给 属性2.哪位高手指点一下 

解决方案 »

  1.   

    屬性1 
            [Bindable(true)]
            [Category("自定义信息区")]
            [Browsable(true)]
            [Description("綁定實例對象對象名")]
            [DefaultValue("")]
            public string BindEntityName
            {
                get {  }
                set {  }
            }
            [Bindable(true)]
            [Category("自定义信息区")]
            [Browsable(true)]
            [Description("綁定實例對象對象屬性名稱")]
            [DefaultValue("")]
    屬性2    public string BindEntityPropertyName
            {
                get {  }
                set {  }
            }具體的屬性的類型是否為string 在再議。現在如果我把一個重寫了的Textbox拖入頁面中的話。那么在它的Properties 視圖中 就會 多出兩個屬性一個是 BindEntityName 一個是 BindEntityPropertyName 。假設有下面一個classpublic class person 
    {
      public string Name
      {
        .....
      }
      public string Age
     {
      ......
      }
    }當我在BindEntityName 輸入 “person” 以後 。BindEntityPropertyName 會自動綁定 Name Age 兩個item 提供用戶選擇。用戶可以選任意一個 賦給 BindEntityPropertyName 屬性。
      

  2.   

    用继承吧
    自己定义个类继承Button然后添加工具栏里
    新建一个名为NewButton的类
        class NewButton:System.Windows.Forms.Button
        {
            private string className;
            private string classValue;
            /// <summary>
            /// ClassName
            /// </summary>
            public string ClassName
            {
                get { return className; }
                set { className = value; }
            }
            /// <summary>
            /// Class的值
            /// </summary>
            public string ClassValue
            {
                get { return classValue; }
                set { classValue = value; }
            }
        }重新生成解决方案工具栏里顶部会出现这个自定义的NewButton
      

  3.   

     public class CTCBTextBox : TextBox
    {
           [Bindable(true)] 
            [Category("自定义信息区")] 
            [Browsable(true)] 
            [Description("綁定實例對象對象名")] 
            [DefaultValue("")] 
            public string BindEntityName 
            { 
                get {  } 
                set {  } 
            } 
            [Bindable(true)] 
            [Category("自定义信息区")] 
            [Browsable(true)] 
            [Description("綁定實例對象對象屬性名稱")] 
            [DefaultValue("")] 
           public string BindEntityPropertyName 
            { 
                get {  } 
                set {  } 
            } }當然要繼承 不繼承重寫誰呢。
      

  4.   

            [Bindable(true)] 
            [Category("自定义信息区")] 
            [Browsable(true)] 
            [Description("綁定實例對象對象屬性名稱")] 
            [DefaultValue("")] 
    楼上的兄台~~这些要是生成DLL在其他地方应用 描述还在吗?
      

  5.   

    兄弟,我怎么看着就像一个google suggest呢?看起来难度不小。
    得有一个keypress事件,然后有个查找,然后对找到的类反射获取属性
      

  6.   

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
    using FSSoft.Common;
    using System.Reflection;
    namespace FSSoft.Web.Controls
    {
    /// <summary>
    /// 文本框WEB控件。
    /// </summary>
    /// <res>JS内需有TrimControl函数。</res>
    [DefaultProperty("IMEDisabled"),
    ToolboxData("<{0}:CTextBox runat=server></{0}:CTextBox>")]
    public class CTextBox : System.Web.UI.WebControls.TextBox, IPostBackEventHandler
    {
    /// <summary>
    /// 修改TextChanged事件。
    /// </summary>
    /// <param name="e">EventArgs参数。</param>
    protected override void OnTextChanged(EventArgs e)
    {
    base.Text=base.Text.Trim();
    base.OnTextChanged (e);
    }
    private bool imeDisabled=false;
    /// <summary>
    /// 输入法设置。
    /// </summary>
    [
    Category("Behavior"),
    Description("输入法设置。")
    ]
    public bool IMEDisabled
    {
    set
    {
    imeDisabled=value;
    }
    get
    {
    if(base.TextMode==TextBoxMode.Password)
    {
    imeDisabled=true;
    }
    return imeDisabled;
    }
    }
    private bool onpaste=true;
    /// <summary>
    /// 设置或取得能否进行文本粘贴。
    /// </summary>
    [
    Category("Behavior"),
    Description("设置或取得能否进行文本粘贴。")
    ]
    public bool Onpost
    {
    set
    {
    onpaste=value;
    }
    get
    {
    if(base.ReadOnly==true||base.Enabled==false)
    {
    onpaste=false;
    }
    if(base.TextMode==TextBoxMode.Password)
    {
    onpaste=false;
    }
    return onpaste;
    }
    }
    /// <summary>
    /// 设置或取得能否拖拽文本到控件内。
    /// </summary>
    [
    Category("Behavior"),
    Description("设置或取得能否拖拽文本到控件内。")
    ]
    public bool Ondrop
    {
    get
    {
    return false;
    }
    }
    private Textalign textalign;
    /// <summary>
    /// 文本框文本对齐方式。
    /// </summary>
    [
    Category("Appearance"),
    Description("文本框文本对齐方式设置。")
    ]
    public virtual Textalign TBTextAlign
    {
    set
    {
    textalign=value;
    }
    get
    {
    return textalign;
    }
            }        #region 焦点相关
            private bool isFocusPostPack = false;
            /// <summary>
            /// 设置是否获得焦点就执行提交。
            /// </summary>
            [
            Category("Behavior"),
            Description("设置是否获得焦点就执行提交。")
            ]
            public virtual bool IsFocusPostPack
            {
                set
                {
                    isFocusPostPack = value;
                }
                get
                {
                    return isFocusPostPack;
                }
            }
            private object EventFocus = new object();
            /// <summary>
            /// 处理Focus事件句柄。
            /// </summary>
            public new event EventHandler Focus
            {
                add
                {
                    Events.AddHandler(EventFocus, value);
                }
                remove
                {
                    Events.RemoveHandler(EventFocus, value);
                }
            }
            /// <summary>
            /// 定义Focus事件。
            /// </summary>
            /// <param name="e">事件对象。</param>
            protected virtual void onFocus(EventArgs e)
            {
                EventHandler focusHandler = (EventHandler)Events[EventFocus];
                if (focusHandler != null)
                {
                    focusHandler(this, e);
                }
            }
            /// <summary>
            /// 实现IPostBackEventHandler接口。
            /// </summary>
            /// <param name="eventArgument"></param>
            void IPostBackEventHandler.RaisePostBackEvent(string eventArgument)
            {
                onFocus(EventArgs.Empty);
            }
            #endregion
            
            /// <summary>
    /// 属性修改。
    /// </summary>
    /// <param name="e"></param>
    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);
    base.Attributes.Add("onblur","TrimControl(this);");
    if(IMEDisabled)
    {
    base.Style.Add("ime-mode","disabled");
    }
    if(TBTextAlign!=Textalign.NoSet)
    {
    base.Style.Add("text-align",TBTextAlign.ToString());
    }
    if(!Onpost)
    {
    base.Attributes.Add("onpaste","return false");
    }
    if(!Ondrop)
    {
    base.Attributes.Add("ondrop", "return false");
    }
                if (IsFocusPostPack)
                {
                    base.Attributes.Add("onfocus", Page.GetPostBackEventReference(this));
                }
    }
    }
    }
    参考下
      

  7.   

    上面的不是我写。我只是从原先我们项目找到的。生产DLL了。
      

  8.   

    设计时需要 只能再写一个 desinger类了
    可继承System.Web.UI.Design.WebControls.PanelDesigner
    重写public override string GetDesignTimeHtml() 这个方法,实现设计时样式,在这里面判断什么时候加载你
    的textbox样式你的textbox类  [DefaultProperty("")]
        [DefaultEvent("")]
        [ParseChildren(false)]
        [PersistChildren(false)]
        [Description("分页控件")]
        [Designer(typeof(//你的designer类))]//这里头引用你的designer就over了
        [ToolboxData("<{0}:textbox runat=server></{0}:textbox >")]
        public class yourtextbox :xxxx, IPostBackEventHandler, IPostBackDataHandler
        {
      

  9.   

    可继承System.Web.UI.Design.WebControls.PanelDesigner 
    重写public override string GetDesignTimeHtml() 这个方法,实现设计时样式,在这里面判断什么时候加载你 
    的textbox样式 
    ==================
    确切的来说应该是继承ControlDesigner,楼主做的不是容器控件,不需要PanelDesigner,
    重写GetDesignTimeHtml只是设计时支持的一个样式呈现,人家需要的是属性管理器里面的属性联动
      

  10.   

    第一步問題 解決了 謝謝大家的支持 我把 code 貼個大家 
    [Bindable(true)] 
            [Category("自定义信息区")] 
            [Browsable(true)] 
            [Description("綁定實例對象對象名")] 
            [DefaultValue("")] 
            public string BindEntityName 
            { 
                get { return ViewState["BindEntityName"] == null ? "" : (string)ViewState["BindEntityName"]; } 
                set { ViewState["BindEntityName"] = value; } 
            }         [Bindable(true)] 
            [Category("自定义信息区")] 
            [Browsable(true)] 
            [Description("綁定實例對象對象屬性名稱")] 
            [DefaultValue("")] 
            [TypeConverter(typeof(EntityConverter))]       
            public string BindEntityPropertyName 
            { 
                get 
                { 
                    return ViewState["BindEntityPropertyName"] == null ? "" : (string)ViewState["BindEntityPropertyName"]; 
                } 
                set { ViewState["BindEntityPropertyName"] = value; } 
                
            } public class EntityConverter : TypeConverter 
        { 
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
            { 
                return true; 
            } 
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
            { 
                return true; 
            } 
            public override TypeConverter.StandardValuesCollection  GetStandardValues(ITypeDescriptorContext context) 
            { 
                
                   List<string> values = new List<string>(); 
                   if (context != null) 
                   { 
                       CTCBTextBox control = context.Instance as CTCBTextBox; 
                       
                       if (control != null) 
                       { 
                           string className = control.BindEntityName;                        if (className != "") 
                           { 
                                  try
                                  {
                                   Assembly assembly = Assembly.GetAssembly(typeof(EntityConverter));
                                   Type t = assembly.GetType("CTCBERP.Entiy." + className);
                                   PropertyInfo[] objPropertiesArray = t.GetProperties();                               foreach (PropertyInfo info in objPropertiesArray)
                                   {
                                       values.Add(info.Name);
                                   }
                                 } 
                               }
                               catch
                               {
                                   return base.GetStandardValues(context);
                               }
                           }
                            return new StandardValuesCollection(values);
                       }
                   }
                   return base.GetStandardValues(context);
            }