2 Replies - 6216 Views - Last Post: 26 May 2009 - 04:54 AM Rate Topic: -----

#1 plnelson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 11-February 09

Way to add enums to custom control properties?

Posted 25 May 2009 - 09:06 PM

What is the correct way to add an enumerated type to a custom control property so that the client can select a choice of enumerations in the control's Properties setting at Design Time?

I have a custom button control and I want the client to select a button style from an enumerated range of values:

	   public enum BUTTONSTYLE { Style_Solid, Style_GradientA, Style_GradientB, Style_Image, Style_Liquid };



But when I try to expose it thusly:
		[DefaultValue( BUTTONSTYLE.Style_Solid)]
		[Category("Appearance")]
		[Browsable(true)]
		[Description("Sets style of the button")]
		public BUTTONSTYLE newbuttonstyle
		{
			get
			{
				return newbuttonstyle;
			}
			set
			{
				newbuttonstyle = value;
			}
		}


Visual Studio 2005 crashes and disappears without any error messages as soon as I drag and drop the control onto a form!
It leaves nothing in the Event Log and the control disappears from the toolbox! What an I doing wrong and how do I debug this?

My button already has other (non-enum) custom properties that work just fine.

Thanks in advance for any insights.

(PS - I've been using Visual Studio 2005 since, well, 2005, and this is the fist time I've ever actually crashed it!)

Is This A Good Question/Topic? 0
  • +

Replies To: Way to add enums to custom control properties?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 3873
  • View blog
  • Posts: 11,408
  • Joined: 18-April 07

Re: Way to add enums to custom control properties?

Posted 25 May 2009 - 11:16 PM

So you created a private member variable called "newbuttonstyle" as well in the control? You really shouldn't name it the same as a function... even if it works it is bad style.

There are three things you need in your control for this to work...

1) Declare the Enum - check
2) Create a public property which returns the Enum - check
3) You have a private enum variable of type "BUTTONSTYLE" which you apparently have also called newbuttonstyle?? I don't see where you are declaring this.

Once you have these three things in place, then you should be all good. Make sure you name your private enum variable something different than the function name just for good measure.

:)
Was This Post Helpful? 0
  • +
  • -

#3 plnelson  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 11-February 09

Re: Way to add enums to custom control properties?

Posted 26 May 2009 - 04:54 AM

Yes, this was a typo - I normally prevent these things with a naming convention but I left off a capitalization. Thanks!

I'm surprised that the compiler didn't flag this when the control was being built - I might have expected a CS0102 error or something similar. Was this a legal overloading of the symbol "newbuttonstyle"?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1