c# - 用户控制停靠属性

标签 c# winforms user-controls attributes docking

我正在尝试制作我自己的用户控件并且几乎完成了它,只是想添加一些润色。我希望设计器中的选项“停靠在父容器中”。有谁知道如何做到这一点我找不到例子。我认为这与停靠属性有关。

最佳答案

我还建议查看 DockingAttribute .

[Docking(DockingBehavior.Ask)]
public class MyControl : UserControl
{
    public MyControl() { }
}

这还会在控件的右上角显示“操作箭头”。

此选项早在 .NET 2.0 就可用,如果您只需要“在父容器中停靠/取消停靠”功能,它就会简单得多。在这种情况下,Designer 类就大材小用了。

它还提供了 DockingBehavior.NeverDockingBehavior.AutoDock 选项。 Never 不显示箭头并以其默认的 Dock 行为加载新控件,而 AutoDock 显示箭头但自动将控件停靠在 as 填写

PS: Sorry about necromancing a thread. I was looking for a similar solution, and this was the first thing that popped up on Google. The Designer attributes gave me an idea, so I started digging around and found DockingAttribute, which seemed far cleaner than the accepted solution with the same requested results. Hopefully this will help someone in the future.

关于c# - 用户控制停靠属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/964421/

相关文章:

c# - 重复使用带有 `using` 语句的局部变量与重复调用非局部变量?

wpf - 无法将页面添加到我的项目

.net - 使用 winform 而不是 WPF 的具体优势

.net - 如何创建使用asp :ListItem as child controls?列表的ASP.NET用户/服务器控件

c# - 数据模板未显示

c# - 实现智能搜索/模糊字符串比较

c# - 合并两个 Linq lambda 表达式

C#:Form.DoubleBuffered = true 会破坏透明度

c# - 如何从用户控件里面关闭一个窗口?

c# - 从类型名称获取可空类型