【问题标题】:Can you add custom properties to child controls of your custom control?您可以将自定义属性添加到自定义控件的子控件吗?
【发布时间】:2013-12-13 09:18:51
【问题描述】:

如果您将 TableLayoutPanel 添加到表单,然后将控件添加到其中一个单元格,则添加的控件在属性窗口中具有额外的属性(例如:Row、RowSpan、Column、ColumnSpan、Cell 等)。

我的问题是,如果您创建自己的自定义控件/组件,是否可以将属性添加到成为自定义控件子级的任何现有控件,例如 TableLayoutPanel 的行为?

【问题讨论】:

  • 是的 - 这些被称为 ExtenderProviders。 ErrorProvider 和 ToolTip 组件就是很好的例子。您还可以将该功能构建到您自己的控件中。它们通常用于向某些控件类型和子控件添加属性。 (这是一个很好的问题,关于该控件如何仅在某物成为它的子对象时才添加属性......我将不得不考虑这一点)。它可以添加到符合条件的控件中,但在成为子控件之前不可见/处于活动状态。
  • 酷,这对我来说是新的研究和学习。谢谢@Plutonix

标签: vb.net winforms visual-studio-2012


【解决方案1】:

我猜你正在寻找 ProvideProperty 属性

http://msdn.microsoft.com/en-us/library/d6c1xa43.aspx

在下面的代码中,您可以看到它在 TableLayoutPanel 中的使用方式

[ProvideProperty("ColumnSpan", typeof(Control))]
[ProvideProperty("RowSpan", typeof(Control))]
[ProvideProperty("Row", typeof(Control))] 
[ProvideProperty("Column", typeof(Control))]
[ProvideProperty("CellPosition", typeof(Control))] 
[DefaultProperty("ColumnCount")] 
[DesignerSerializer("System.Windows.Forms.Design.TableLayoutPanelCodeDomSerializer, " + AssemblyRef.SystemDesign, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + AssemblyRef.SystemDesign)]
[Docking(DockingBehavior.Never)] 
[Designer("System.Windows.Forms.Design.TableLayoutPanelDesigner, " + AssemblyRef.SystemDesign)]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[SRDescription(SR.DescriptionTableLayoutPanel)] 
public class TableLayoutPanel : Panel, IExtenderProvider {

【讨论】:

    猜你喜欢
    • 2011-06-27
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 2014-11-26
    • 2013-01-09
    • 2011-03-12
    • 2012-04-13
    • 1970-01-01
    相关资源
    最近更新 更多