Lock size property problems in a custom control

G

Guest

I made a custom control and I want to make impossible to resize it.
I follow these steps:
- I use a ControlDesigner (overridden SelectionRules)
- I hide the public Size property and make it readonly
- I override the protected DefaultSize property

and I achieve the correct behaviour in the designer.

The problem is that at runtime the control is many times bigger the size specified in the size property and I don't understand where this wrong size is read.

Does anyone found this problem yet?

Thanks in advance
 
M

Mick Doherty

Instead of hiding and making ReadOnly the Size property, modify the OnResize
method so that your fixed size is restored.

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.Size = New Size(50, 23)
End Sub

protected override void OnResize(EventArgs e)
{
base.Size = new Size(50, 23);
}

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


GG said:
I made a custom control and I want to make impossible to resize it.
I follow these steps:
- I use a ControlDesigner (overridden SelectionRules)
- I hide the public Size property and make it readonly
- I override the protected DefaultSize property

and I achieve the correct behaviour in the designer.

The problem is that at runtime the control is many times bigger the size
specified in the size property and I don't understand where this wrong size
is read.
 
G

Guest

Thanks Mick but I found another solution: in the constructor of the control I insert

this.Bounds = new Rectangle(this.Location.X, this.Location.Y, this.defaultSize.Width, this.defaultSize.Height);

and now all things works properly.

I forgot to mention that i'm working with compact framework so the defaultSize property is not available.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top