设置 TFrame 的站点属性
我正在尝试在 C# 中创建一个 CustomControl,其中包含一个 Delphi TFrame,可以将其从 VisualStudio 工具箱拖到窗体上。我已经正确工作了这么多,但是当我尝试调整大小时,由于 TFrame 未在设计模式下运行(它尝试访问框架上数据网格的事件处理程序),会发生控制错误。
我在 Delphi 中创建了一个 TFrame 对象,其中包含各种控件(数据网格、组合框等),并在 C# 中创建了一个 CustomControl,其中包含 TFrame 对象。
为了解决这个问题,我认为我需要设置 TFrame 对象的 Site 属性,以便 DesignMode 为 true。我该怎么做呢?
我知道我可以通过在每个方法的开头检查 LicenseManager.UsageMode 是否设置为 DesignTime 来解决这个问题,但这似乎是解决问题的一种非常糟糕的方法。因此,如果可能的话,我希望正确设置站点属性。
我正在使用 CodeGear RAD Studio 2007 和 Visual Studio 2008。
提前致谢
I am attempting to create a CustomControl in C# which contains a Delphi TFrame, which can be dragged from the VisualStudio toolbox onto a Form. This much I have working correctly, however when I attempt to resize the control errors occur due to the TFrame not running in design mode (it attempts to access the event handlers for a data grid on the frame).
I have created a TFrame object in Delphi which contains various controls (data grid, combobox etc), and a CustomControl in C# which contains the TFrame object.
To get around this problem I think I need to set the Site property of the TFrame object, so that DesignMode is true. How can I go about doing this?
I know I can get around this problem by checking at the start of each method if the LicenseManager.UsageMode is set to DesignTime, but this seems a very bad way of solving the problem. So if possible I would like to get the site property set correctly.
I am using CodeGear RAD Studio 2007 and Visual Studio 2008.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,此问题是由 Visual Studio 中的一个错误引起的,其中在构造函数或 UserControl 中创建的组件上永远不会设置 DesignMode 和 Site 属性。因此 DesignMode 属性始终为 false。
有几种建议的解决方案,所有这些解决方案都涉及向任何事件处理程序或方法添加测试,其中代码应仅在运行时执行。第一个选项是检查 LicenseManager.UsageMode 属性,第二个选项是检查执行进程的名称(例如,如果它是“devenv”,则它是设计时间)。
Turns out this problem is caused by a bug within Visual Studio where the DesignMode and Site property never gets set on components created within a constructor or a UserControl. Therefore the DesignMode property is always false.
There are several proposed solutions all of them involve adding a test to any event handlers or methods where code should only be executed at runtime. The first option is to check the LicenseManager.UsageMode property, and the second option is to check the name of the executing process (e.g. if its "devenv" then its design time).