views:

2084

answers:

4

I have a usercontrol that has several public properties. These properties automatically show up in the properties window of the VS2005 designer under the "Misc" category. Except two of the properties which are enumerations don't show up correctly.

The first on uses the following enum:

public enum VerticalControlAlign
{
    Center,
    Top,
    Bottom
}

This does not show up in the designer at all.

The second uses this enum:

public enum AutoSizeMode
{
    None,
    KeepInControl
}

This one shows up, but the designer seems to think it's a bool and only shows True and False. And when you build a project using the controls it will say that it can't convert type bool to AutoSizeMode.

Also, these enums are declared globably to the Namespace, so they are accessible everywhere.

Any ideas?

A: 

For starters, the second enum, AutoSizeMode is declared in System.Windows.Forms. So that might cause the designer some issues.

Secondly, you might find the following page on MSDN useful:

http://msdn.microsoft.com/en-us/library/tk67c2t8.aspx

Mark Ingram
I am suffering from the problem in the first example - my enums don't show up at all. This answer doesn't even attempt to address that issue.
Tim
A: 

Some things to try (designer mode in VS2005 I have found to be somewhat flaky):

  1. Open your web.config and add: batch="false" to your <compilation> tag.
  2. Try setting defaults to your enums:

    public enum VerticalControlAlign { Center = 0, Top = 1, Bottom = 2 }

Thunder3
This is WinForms NOT WebForms
Adam Haile
A: 

You do not need to make your enums global in order for them to be visible in the designer.

Clarify please:

  1. if you add another value to your AutoSizeMode enum, does it still appear as a boolean?
  2. If (instead) you change the name of enum, does it still appear as a boolean?
Craig Eddy
A: 

I made a little test with your problem (I'm not sure if I understood it correctly), and these properties shows up in the designer correctly, and all enums are shown appropriately. If this isn't what you're looking for, then please explain yourself further.

Don't get hang up on the _Ugly part thrown in there. I just used it for a quick test.

using System.ComponentModel;
using System.Windows.Forms;

namespace SampleApplication
{
    public partial class CustomUserControl : UserControl
    {
        public CustomUserControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// We're hiding AutoSizeMode in UserControl here.
        /// </summary>
        public new enum AutoSizeMode { None, KeepInControl }
        public enum VerticalControlAlign { Center, Top, Bottom }

        /// <summary>
        /// Note that you cannot have a property  
        /// called VerticalControlAlign if it is   
        /// already defined in the scope.
        /// </summary>
        [DisplayName("VerticalControlAlign")]
        [Category("stackoverflow.com")]
        [Description("Sets the vertical control align")]
        public VerticalControlAlign VerticalControlAlign_Ugly
        {
            get { return m_align; }
            set { m_align = value; }
        }
        private VerticalControlAlign m_align;        

        /// <summary>
        /// Note that you cannot have a property  
        /// called AutoSizeMode if it is   
        /// already defined in the scope.
        /// </summary>
        [DisplayName("AutoSizeMode")]
        [Category("stackoverflow.com")]
        [Description("Sets the auto size mode")]
        public AutoSizeMode AutoSizeMode_Ugly
        {
            get { return m_autoSize; }
            set { m_autoSize = value; }
        }
        private AutoSizeMode m_autoSize;    
    }
}
Statement