C# usercontrol如何访问所有子控件
我定义了一个自定义面板,里面有一个表格布局面板。但是,当我在 winform 上使用此控件时,我无法访问表布局面板属性。 (例如,我想在单元格中添加一列或停靠其他控件)。我尝试将修饰符属性更改为public,但仍然不起作用。我该怎么做才能查看和更改面板布局属性?
事实上,问题可以更通用:如何访问/修改/移动自定义用户控件中包含的控件?
谢谢
I defined a custom panel with a table layout panel inside. However when I used this control on a winform I do not have access to the table layout panel properties. (I want for instance add a column or dock an other control in a cell). I try to changed the modifier property to public, but it still does not work. What can I do in order to see and change the panel layout properties ?
In fact, the question can be more generic : how to access/modify/move controls contained in a custom usercontrol ?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在用户控件中公开要修改的属性。例如,要更改表布局控件的列计数属性,您必须从用户控件公开 ColumnCount 属性:
然后您还可以开始使用一些属性来控制用户控件在 Visual Studio 中的显示方式,例如例如,上面可以这样修改:
这将整个用户控件的默认属性设置为“ColumnCount”,并给列计数属性一个描述,默认值为2,并设置它应该显示在什么类别中设计器的属性窗口。用户控件还可以做很多事情来添加设计时支持。
You need to expose the properties you want to modify in your user control. For example, to change the column count property of the table layout control, from your user control, you have to expose the ColumnCount property:
You can also then start to use some attributes to control how your user control is displayed in Visual Studio, for example, the above can be modified like so:
This sets the default property of the entire user control to "ColumnCount", and gives the column count property a description, a default value of 2, and sets in what category it should be displayed in the designer's properties window. There is a lot more that can do with a user control to add design time support.