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


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.2K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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.
Paul Chase
Paul Chase
StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Gregg,

Did you set the designerserialization attribute of the property?

<Category("Data Properties"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _

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


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.2K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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!
Paul Chase
Paul Chase
StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
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).

Attachments
aa.png (149 views, 17.00 KB)
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.2K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks Paul. Between you and Trent I actually figured this out!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search