Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Rezise usercontrol by width only

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Executor - 22 Sep 2007 08:29 GMT
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?
Alberto Poblacion - 22 Sep 2007 08:57 GMT
>    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.
Family Tree Mike - 22 Sep 2007 14:06 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.