asp.net控件设计时支持(4)
tr.Cells.Add(tc);
t.Rows.Add(tr);
Controls.Add(t);
}
}
步骤 (1).自定义一个从CompositeControlDesigner继承的类,CompositeControlDesigner为复合控件提供设计时支持,我们需要重写CreateChildControl方法 protected override void CreateChildControls() { base.CreateChildControls(); Table t = (Table)myControl.Controls[0]; if (t != null) { t.Rows[0].Cells[0].BackColor = Color.Red; //定义区域事件触发对象 t.Rows[0].Cells[0].Attributes[DesignerRegion.DesignerRegionAttributeName] = "0"; t.Rows[0].Cells[1].BackColor = Color.Green; t.Rows[0].Cells[1].Attributes[DesignerRegion.DesignerRegionAttributeName] = "1"; t.Rows[1].Cells[0].BackColor = Color.Blue; t.Rows[1].Cells[0].Attributes[DesignerRegion.DesignerRegionAttributeName] = "2"; } } 主要工作就是为Click事件定义了区域事件出发对象,方法则是为控件属性集合提供DesignerRegion.DesignerRegionAttributeName属性,注意值0,1,2和GetDesignTimeHtml方法中的DesignerRegionCollection集合顺序是一样的,不可以弄乱,按上面效果图 你可以看到0和1是触发区域事件的对象(即View1和View2),2则是编辑区域 (2)添加区域,接同上面步骤,在GetDesignTimeHtml方法中完成,这里命名哦,跟各个操作步骤紧密联系在一起的 public override String GetDesignTimeHtml(DesignerRegionCollection regions) (4)更新和获取模板数据操作 //获取模板内部数据 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |