Rezise usercontrol by width only

E

Executor

Hi to all,

I have created a user control for which I want only the width property
be available for resizing.

I have tried:
namespace TestControl
{
public class Class1
{
public override double Height
{ get
{
base;
}
}
}
}
But on compile I get:
Not suitable method found for override.

How do I do this?
 
A

Alberto Poblacion

Executor said:
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.
 
G

Guest

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.
 
E

Executor

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.
 

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