最新评论
Visiual
属性应在初始化代码中保持,在设计器中仅对该属性进行赋值,设计器生成代码
testcontrolnull.entity entity1 = new testcontrolnull.entity();
entity1.MyProperty = new decimal(new int[] {
0,
0,
0,
0});
this.userControl21.E = entity1;//先生成entity1对象,再对MyProperty整体进行设置
Content
应为分配给该属性的对象的每个公共属性(而非隐藏属性)生成初始化代码
在设计器中,可以对该属性的各个属性进行设置。
对MyProperty各个属性进行单独设置,设计器生成代码
this.userControl21.E.ID = new decimal(new int[] {
0,
0,
0,
0});//对ID设置
this.userControl21.E.Name = null;//对Name设置
Hidden
标示属性不在设计器中显示,设计器不必自动生成对该属性赋值的代码。
使用content属性,entity类的接口改变,会导致form类出错,hidden不会。
谢谢哈,已经按照这个方法搞定了。之前我也用过DesignerSerializationVisibility,需要将控件删除重新拖拽到窗体才看到效果,当时没有重新拖拽,所以以为这个不行哦。
[DesignerSerializationVisibility(0)]
public entity E
{
get { return e; }
set { e = value; }
}
为什么不仔细看看父类的metadata呢?
所有的usercontrol的父都是control继承,看看其metadata中的定义
...
// 摘要:
// 获取分配给该控件的 System.Windows.Forms.AccessibleObject。
//
// 返回结果:
// 分配给该控件的 System.Windows.Forms.AccessibleObject。
[DesignerSerializationVisibility(0)]
[Browsable(false)]
[EditorBrowsable(2)]
public AccessibleObject AccessibilityObject { get; }
...
不就一目了然了吗?
当然我可以手动在Designer.cs中删除那些无用的生成代码,但是难道没有更好的方法?我看framework的设计控件在拖动到设计器时也会对某些在设计器中没有用到的属性进行设置,比喻this.btnCancle.DialogResult = System.Windows.Forms.DialogResult.Cancel;但是很多属性他没有进行设置,不清楚如何控制呢。
我写控件也是单个 .ascx 来写
.net 设计时生成不友好,很多不想要的东西它都去生成
目前我也没找到相应办法
因为我写的项目都已经包含到 <asp:Content 中,所以设计时根本看不到内容,也不能设计
我的做法是把以往的代码 COPY 来 COPY 去
<%@ Control Language="C#" ClassName="chk_news_status" %>
<script runat="server">
public string Value {
get { return hidfld_news_status.Value; }
set {
int tryint;
int.TryParse(value, out tryint);
hidfld_news_status.Value = tryint.ToString();
}
}
</script>
<asp:HiddenField ID="hidfld_news_status" runat="server" />
<script type="text/javascript">
var cs = ['审核', '删除', '评论'], data_status = 0;
with($('<%= hidfld_news_status.ClientID %>')) {
if (isNaN(parseInt(value, 10))) value = 0;
data_status = parseInt(value, 10);
};
for(var a = 0; a < cs.length; a++) {
document.write('<input type=checkbox id=news_status_checkbox_' + (a + 1) + ((data_status & Math.pow(2, a)) == Math.pow(2, a) ? ' checked' : '') +
' onclick="var tb = $(\'<%= hidfld_news_status.ClientID %>\'); tb.value = parseInt(tb.value, 10) + (this.checked ? 1 : -1) * ' + Math.pow(2, a) +
'"><label for=news_status_checkbox_' + (a + 1) + '>' + cs[a] + '</label>');
}
</script>
