How to create a custom property in User Control of enum type in C#
Hi,
I am very much new to .net Compact Framework.
I am creating a user control.I have to expose a custom property to the user so that he can select the value of the property among a predefined values.I found that we have to use enum.
That is I want to make the property in the designer be a dropdown list.
I have tried with the following code..
Heee ??? Never seen what this should handle. You are overwriting your internal value one after the other so at least you only and everytime will get yellow. You don't need to do enums if you dont want you can use your coloor class itself, because as it seems to me you have your own self declared colors. Look how this works The theme is called TypeConverter and I have written about that in my article series Part1 about how to create a dockable panel
The link you can find in the bottom of this page. This series explains the basics of how to create a userdefined control and by that also explains how to have your own classes used as types in the property Grid Easy to read because done for C# beginners. Lots of pictures
Last edited by JonnyPoet; June 1st, 2009 at 11:01 AM.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Re: How to create a custom property in User Control of enum type in C#
If you simple want to use enum your code should look like
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace CGColorControlTest {
// defined outside the class !
public enum ArrowColor {Red, Green,Magenta, Pink,Orange,Black,Yellow};
public partial class MyControl : UserControl {
private ArrowColor _foreColor;
public MyControl() {
InitializeComponent();
}
[Browsable(true)]
public ArrowColor ForeColor {
get { return _foreColor; }
set { _foreColor = value; }
}
}
}
The result looks this way. And BTW Please use codetags as its in our forum rules. Any formatting goes lost when not using them and nobody wants to read codesausage
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ? My latest articles : Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Re: How to create a custom property in User Control of enum type in C#
thanks for the correction Johnny..
opps!! some how i had messed up while replying to that post..yes.. all the values were going to be overwritten and only the last value would had been returned...
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.