views:

74

answers:

2

Hello!

I'm developing a Windows Mobile WinForm app with C# and .Net Compact Framework 2.0 SP2.

I have a control that inhertit from System.Windows.Form.Control that I want to make private Size property. How can I do that?

I've tried this:

new private Size;

But it doesn't compile.

Any idea?

+1  A: 

This will work:

    new private Size Size
    {
        get { return Size; }
        set { Size = value; }
    }

However hiding the Size property isn't recommended. You basically break the contract that is expected from a Control and you may get runtime exceptions when other classes are trying to interact with it.

kgiannakakis
Maybe doing private the set part of the property can solve the problem you've exposed. My control contains an image and I want that the control has the same size of the image and none can change its size.
VansFannel
+2  A: 

Just create a public property with the same name Size in your control:

public Size Size
{
    get { return base.Size; }
    set { base.Size = value; }
}

Then you can do something in the setter to prevent your control size from being changed to a size that doesn't match your image.

tomlog