> public class Class1
> {
> public override double Height
> [...]
> Not suitable method found for override.
Well, your "Class1" is not inheriting from anything, so it's no wonder
that you can't override Height.
You can inherit from Control or any of its derived classes, but you are
still not going to be able to override Height because it is not marked as
virtual in the Control class. Instead of overriding, you can shadow the
property by using the "new" keyword (public new double Height), but this
will not prevent the control from being resized by code that casts into the
parent class.
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.
> Hi to all,
>
[quoted text clipped - 18 lines]
>
> How do I do this?
Executor - 27 Sep 2007 20:41 GMT
On 22 sep, 15:06, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.com> wrote:
> As Alberto said, the supplied code isn't for a control.
>
[quoted text clipped - 5 lines]
> 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.