Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Form designer & setting visibility
 

Form designer & setting visibility

Hi,
I used FormDesigner from #Develop in my test application. I have a problem when I try to deserialize (XML --> design), that controls, which have visible=false are not displayed on the design form. I think the problem comes, when control is created and placed in a container where comes its designer initialization. After that, all its properties are deserialized and set on this new object.

I call it like:
// ... this creates component and places it in design container
host.CreateComponent(newObject.GetType(), componentName);


// ... here we set properties like position, size etc. including visible
// after this, control is invisible when set to false
SetUpObject(newObject);

---------------------------------------
in container class (public class DesignComponentContainer : IContainer)
is a method:
public void Add(IComponent component, string name)
{
...
    component.Site = new ComponentSite(host, component);
    designer = TypeDescriptor.CreateDesigner(component, typeof(IDesigner));
    designer.Initialize(component);
}
---------------------------------------
I tried to setup the object first and then to add it to the container, but it didn't work at all.

So, after all this long description comes my question - when should I set properties of the control (mainly visible attribute) so that I can see it on the FormDesigner, but so that  PropertyBrowser display correct value of false?

I hope that people who know about Design Time can understand me...

thanks for any help
MigrationUser 1  Monday, June 02, 2003 3:47 PM
Make sure that the code that sets the visible property goes through TypeDescriptor to access the properties.  Don't use System.Reflection, and don't go straight to the Visible property.

The way that properties like Visible work at design time is that the control's designer "shadows" the property:  it creates a duplicate property called Visible on the designer class, and replaces the original control's property with the one on the designer.   This type of replacement only works if you get to properties through TypeDescriptor.

The property window always uses typeDescriptor to get and set properties, while the control designer itself typically talks to the control's properties directly.  So the control designer sets its "shadowed" visible property to the orignal value stored in the control, and then it sets the control to Visible directly.  

I hope this has been some help.  The design time is very powerful, but there is a pretty significant learning curve to learn all the terminology and techniques.  We're working on making that better...
MigrationUser 1  Friday, July 11, 2003 1:08 AM
FYI, here's a simple Designer that "shadows" the Visible Property as Brian mentioned...sorry, I'm just cutting and pasting...it's in VB.NET  :P 


Public Class MyControlDesigner
Inherits ComponentDesigner

Public Property Visible() As Boolean
Get
Return DirectCast(Me.ShadowProperties("Visible"), Boolean)
End Get
Set(ByVal Value As Boolean)
Me.ShadowProperties("Visible") = Value
End Set
End Property

Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
MyBase.Initialize(component)

With DirectCast(component, MyControl)
Me.Visible = .Visible
.Visible = True
End With
End Sub

Protected Overloads Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary)
MyBase.PreFilterProperties(properties)
properties("Visible") = TypeDescriptor.CreateProperty(GetType(ControlArrayDesigner), CType(properties("Visible"), PropertyDescriptor))
End Sub

End Class


Also, this was taken from my <a href="http://www.windowsforms.net/ControlGallery/ControlDetail.aspx?Control=251&tabindex=9">ControlArray</a> Component that you might want to check out as it comes with all the designer code to play with!  :)  It has shadowed properties, design time only properties, using design services, etc
MigrationUser 1  Tuesday, July 15, 2003 2:26 AM

You can use google to search for other answers

Custom Search

More Threads

• Controls position on window resizings...
• Custom control displays differently in TabPage
• Display a string on an AVI movie
• Form Designer wont load!
• Resx problem
• AcceptButton like property
• Windows Forms
• input number only in gridtextbox cell
• Can one use glyphs to manage user-interface with something other than a full-feldged control
• Custom UITypeEditor and the PropertyGrid