Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No code generated for properties in custom class

Status
Not open for further replies.

MKuiper

Programmer
Jan 29, 2002
364
NL
I've created a subclass of a button including another class:

Code:
public class MyProperties : System.ComponentModel.Components
{
    public bool MyProperty1
    { 
        get { ... }
        set { ... }
    }
}

public class MyButton : Button
{
    private MyProperties myProperties;
    public MyProperties MyProp
    {
        get { return myProperties; }
    }

    MyButton ( )
    {
        myProperties = new MyProperties ( );
    }
}

Problem is, when I add a MyButton to a form, the designer lets me access (set) MyProp->MyProperty1. In the designer the MyButton control is responding correct to the setting of the property.
But no code is generated, so the properties are lost at runtime. Btw, this is about VS2005, not the Beta.
What requirement am I missing ?

Marcel
 
MyButton ( )
{
myProperties = new MyProperties ( );
}


it's possible that this section is overwriting whatever changes you are making at design time.

Try making your code:

private MyProperties myProperties = new MyProperties();

MyButton()
{
}
 
JurkMonkey,

Your idea was worth trying, but it doesn't help. Pity. Any other ideas? I thought perhaps MyProperties must be derived from another thing, or maybe it must implement some interface. Can't find it.

Marcel
 
Solved. For those interested, here's the answer.

Code:
public class MyProperties : System.ComponentModel.Components
{
    public bool MyProperty1
    {
        get { ... }
        set { ... }
    }
}

public class MyButton : Button
{
    private MyProperties myProperties;

[COLOR=red]    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[/color]
    public MyProperties MyProp
    {
        get { return myProperties; }
    }

    MyButton ( )
    {
        myProperties = new MyProperties ( );
    }
}

Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top