As Alberto said, the supplied code isn't for a control.
Assuming you have a control coded/designed, and you want to limit the size
when used on a form, then you can set the minimum and maximum sizes to what
you want. In your case, set the minimum and maximum heights to be the same
value.
If you are trying to control the size inside the control, you will need to
override the events raised by resizing the control.
CUT
Hi there,
Thanks for your info, I now have this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace TestProps
{
public partial class UserControl1 : UserControl
{
public enum eOrientation
{
Horizontal,
Vertical
}
private eOrientation m_Orientation = eOrientation.Vertical;
public UserControl1()
{
InitializeComponent();
}
public eOrientation Orientation
{
get { return m_Orientation; }
set { m_Orientation = value; }
}
public new int Height
{
get { return base.Height; }
set
{
if (m_Orientation == eOrientation.Vertical)
base.Height = value; ;
}
}
public new int Width
{
get { return base.Width; }
set
{
if (m_Orientation == eOrientation.Horizontal)
base.Width = value;
}
}
private void UserControl1_Resize(object sender, EventArgs e)
{
if (m_Orientation == eOrientation.Horizontal)
{
// ToDo: Calculate Height
}
else
{
// ToDo: Calculate Width
}
}
}
}
It seems to work.