Setting the Site Property of TFrame
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), an开发者_运维技巧d 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
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).
精彩评论