Lock size property problems in a custom control

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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.
 
Back
Top