StrataFrame Forum

How to set parent of component to parent form at design time

http://forum.strataframe.net/Topic24948.aspx

By Greg McGuffey - 10/19/2009

I'm trying to get a component to set a ParentForm property at design time and have it serialized. I think you are doing something like this with the ParentContainer property when you implement the IInitOnFormLoad interface, but I'm not figuring it out.



First, is this entirely handled via that property? It appears to be setting the value of the property, when in design mode, but what calls the property in design mode to begin with?



Second, what causes the value to be serialized? In the setter, the component is added to the list of objects that need to be initialized. Is there something special that needs to happen to get it serialized? I'm using C# if that makes difference or requires some extra step.
By Paul Chase - 10/21/2009

Gregg,

Did you set the designerserialization attribute of the property?

<Category("Data Properties"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _

Public Property ReportParameters() As Generic.List(Of ReportParameter)

By Greg McGuffey - 10/21/2009

I hadn't set that, but I didn't need to in any case (it is a simple object, an IParentContainer), so the default is fine.



However, it did prompt me to work up a sample app that eventually allowed me figure it out. In translating the code from VB to C#, I didn't correctly handle this line:



'-- In ComboBox code, ParentContainer Get

If (Not Array.IndexOf(CType(loDesigner.RootComponent, Object).GetType().GetInterfaces() _

  , GetType(MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl)) > -1) _

  AndAlso (loDesigner.RootComponent IsNot Me) Then





The "Not Array.IndexOf(....) > -1" really was making my brain hurt in C# after adding all the parentheses to handle casting and I didn't do that right. I changed it to:



//-- Check the type of the root component - changed from Not > -1 to < 0.

if ((Array.IndexOf( ((object)(loDesigner.RootComponent)).GetType().GetInterfaces(), typeof( IContainerControl ) ) < 0)

  && (loDesigner.RootComponent != this))





Now it works correctly. I'm still trying to figure out how to debug code that is written for the designer...



Thanks for the help!
By Paul Chase - 10/21/2009

Glad you got it.

To debug designer code you can go to the project properties of the project ,then debug and set the start action to stat external progam and point it to your visual studio instance devenv.exe.

Then debug will open a new instance of visual studio, you can then open up a test project and use the designer and debug will hit breakpoints etc in your designer code (type converters custom properties etc).

By Greg McGuffey - 10/28/2009

Thanks Paul. Between you and Trent I actually figured this out!