hi ppl, i have a custom control, and i need a property that have multiple options, its a property that sets the status of the control, and i need to have the next properties:
Active
Inactive
Off
and i thought i could get this with an enum , but i dont get a clue of how to make a property that handles more than 2 options...
am i right can some 1 give me some code pls
mig16

enum Property
amat2to0
Play along, ok
Listing 1 - FlagPropertyDesignerPanel.cs
Listing 2 - FlagPropertyDesigner.cs
Listing 3 - FlagDesigner.cs
Complete source here
Madhu K Nair
I don't understand your problem with "a property handles more that 2 options" but here's some code that might help:
public class UserControl1 : UserControl
{
private ControlStatus status;
public ControlStatus Status
{
get
{
return status;
}
set
{
status = value;
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
switch (status)
{
case ControlStatus.Active:
e.Graphics.FillRectangle(SystemBrushes.Window, ClientRectangle);
break;
case ControlStatus.Inactive:
e.Graphics.FillRectangle(SystemBrushes.Control, ClientRectangle);
break;
case ControlStatus.Off:
e.Graphics.FillRectangle(SystemBrushes.ControlDark, ClientRectangle);
break;
}
}
}
public enum ControlStatus
{
Active,
Inactive,
Off
}
polytx
heres an image of the designer in action:
Klimov Vova
SPGMuthu
Oops. . . I missed your point. I saw "multiple options" on a UserControl . . . thought you needed to make a flag designer.
At any rate, put that code in your "set of tools" its very handy
Utku
hi,
you can do something like this
namespace ConsoleApplication1
{
enum MyEnum {
Off,
Inactive,
Active
}
class Program {
private static int myVar;
public static MyEnum MyProperty
{
get {
return (MyEnum)myVar;
}
set {
myVar = (int)value;
}
}
static void Main(string[] args)
{
MyProperty = MyEnum.Active;
Console.WriteLine(myVar);
MyProperty = MyEnum.Inactive;
Console.WriteLine(MyProperty);
}
}
}
i set myvar as int but you can make it of type MyEnum too and remove the casting from Myproperty
hope this helps