WinForms - 启用设计模式

发布于 2024-08-16 03:40:45 字数 312 浏览 7 评论 0原文

对于 OSS 项目,我尝试以编程方式将控件添加到 WinForms 视图中。并且我想让这些控件像在 Visual Studio 设计器中一样可编辑和调整大小。我一直在尝试使用 Controls.Add(label) 以编程方式添加..但我正在努力弄清楚如何使 UI 可编辑。

我假设它会利用 DesignMode - 但我只能找到这些属性的 getter 而不是 setter。简而言之 - 有没有办法以编程方式在 WinForms 中启用和禁用 DesignMode?

我还没有研究 WPF - 也许它能够有可编辑的控件?

非常感谢,抱歉圣诞节后很痛苦。 时间

For a OSS project, I'm trying to add controls programmatically to a WinForms view.. and I want to make these editable and resizeable as in the Visual Studio Designer. I've been playing around with adding programmatically, using Controls.Add(label).. but I'm struggling to work out how to make the UI editable.

I'm assuming it would make use of DesignMode - but I can only find getters and not setters for these properties. Simply put - is there any way of enabling and disabling DesignMode in WinForms programmatically?

I'm yet to investigate WPF - perhaps that would be able to have editable controls?

Many thanks, sorry to be a pain right after christmas..
T

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

欢烬 2024-08-23 03:40:45

实际上有一种方法可以让 UI 可编辑,就像在 VS 设计器中一样。您必须在表单上托管 winforms 设计器。
此信息可能有帮助:
http:// msdn.microsoft.com/en-us/magazine/cc163634.aspx

Actually there is a way to make UI editable as in VS designer.You have to host the winforms designer on your form.
this info might help:
http://msdn.microsoft.com/en-us/magazine/cc163634.aspx

平安喜乐 2024-08-23 03:40:45

它可以在 WinForm 中使用,由 alexm 解释。不幸的是,对于 WPF 设计器来说,情况并非如此。在那里你必须实现你自己的设计器。

It is available in WinForm as explained by alexm. Unfortunately this is not true for the WPF designer. There you would have to implement your own designer.

亣腦蒛氧 2024-08-23 03:40:45

据我所知,设计器功能是在 Visual Studio 中实现的,而不是 WinForms 运行时库的一部分。 DesignMode 属性是只读的,因为它提供有关执行上下文的信息;这不是可以即时更改的内容(附带说明:此属性是 并不像人们希望的那样易于使用)。

如果您想让 UI 在运行时可编辑(即更改控件的大小/布局),则必须手动实现许多行为(例如 OnMouseDown 处理程序等)。如果您想做一些事情,例如绘制具有可抓取角的边界框,您可能需要深入研究自定义绘图。

我不确定 WPF,因为我对它的经验较少,但是这个问题 on SO 有一些关于在运行时调整控件大小的信息。

As far as I know, the Designer functionality is implemented in Visual Studio, and is not part of the WinForms runtime libraries. The DesignMode property is read-only because it gives information about the execution context; this is not something that can be changed on the fly (as a side note: this property is not as easy to use as one would hope).

If you want to make the UI editable at runtime (i.e. changing the size/layout of controls), you would have to implement a lot of the behavior manually (e.g. OnMouseDown handlers, etc.). If you wanted to do things like drawing bounding boxes with grabbable corners, you might need to delve into custom drawing.

I'm not sure about WPF, as I have much less experience with it, but this question on SO has some information about making controls resizable at runtime.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文