问题大概是这样。 我重写一个TextBox 控件 增加两个属性 。1,一個屬性表示TextBox 綁定的Class name;
2,一個屬性表示 TextBox 绑定Class 的 属性名称想在设计器 里 实现如下效果 当输入1 属性时 2,属性列出该类型的所有属性(下拉选项)用户选一个并赋给 属性2.哪位高手指点一下
2,一個屬性表示 TextBox 绑定Class 的 属性名称想在设计器 里 实现如下效果 当输入1 属性时 2,属性列出该类型的所有属性(下拉选项)用户选一个并赋给 属性2.哪位高手指点一下
解决方案 »
- asp.net 常使用 MasterPage.master吗?
- 求教在框架内登录需要两次的问题
- 大家如何做需求分析的,流程图、用例图、功能节点等等
- datagrid中把成绩小于60的行显示为红色,大于60的显示为绿色,怎么显示(高手指教在线等!!!!)
- 怪了,怎么在纯html页中不能使用include,在asp.net中却能用???????请老师们指点。
- 问在线编辑网页的问题
- 使用DOTNETTEXTBOX 3.4.7的路径设置问题
- 在asp.net中Datagrid的数据导入到指定的Excel中的某行某列,怎么搞
- 求助!我现在用水晶报表push模式,但由于库里的某一字段的记录值是不方便用户阅读的,我写了一函数进行转换,但不知在水晶报表中如何用这
- 请问DATASET存活期????
- 页面传值问题 请高手解答 急~~!!! 在线等
- ObjectDataSource SelectParameters的问题
[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 屬性。
自己定义个类继承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
{
[Bindable(true)]
[Category("自定义信息区")]
[Browsable(true)]
[Description("綁定實例對象對象名")]
[DefaultValue("")]
public string BindEntityName
{
get { }
set { }
}
[Bindable(true)]
[Category("自定义信息区")]
[Browsable(true)]
[Description("綁定實例對象對象屬性名稱")]
[DefaultValue("")]
public string BindEntityPropertyName
{
get { }
set { }
} }當然要繼承 不繼承重寫誰呢。
[Category("自定义信息区")]
[Browsable(true)]
[Description("綁定實例對象對象屬性名稱")]
[DefaultValue("")]
楼上的兄台~~这些要是生成DLL在其他地方应用 描述还在吗?
得有一个keypress事件,然后有个查找,然后对找到的类反射获取属性
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));
}
}
}
}
参考下
可继承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
{
重写public override string GetDesignTimeHtml() 这个方法,实现设计时样式,在这里面判断什么时候加载你
的textbox样式
==================
确切的来说应该是继承ControlDesigner,楼主做的不是容器控件,不需要PanelDesigner,
重写GetDesignTimeHtml只是设计时支持的一个样式呈现,人家需要的是属性管理器里面的属性联动
[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);
}