I have currently the following and I think it is very cumbersome. I generically create different buttons on a form and accomplish it by passing an array of buttons. Each button have a set of properties to setup the button on the fly.
public enum BtnType { bOK , bCancel, bYes, bNo };
public enum bOk { Name = "OKBtn", Text = "OK" }
public enum bCancel { Name = "CancelBtn", Text = "Cancel" }
public enum bYes { Name = "YesBtn", Text = "Cancel" }
public static void SetButtons(BtnType[] _btnType, string onClick)
{
foreach (int i in _btnType)
{
switch (_btnType[i])
{
case BtnType.bOK:
{
btnp.Name = bOk.Name;
btnp.Text = bOk.Text;
}
break;
case BtnType.bCancel:
{
btnp.Name = bCancel.Name;
btnp.Text = bCancel.Text;
}
break;
case BtnType.bYes:
{
btnp.Name = bYes.Name;
btnp.Text = bYes.Text;
}
break;
}
}
Then I call it like this and it will create 2 buttons for me.
SetButtons(new BtnType[] { BtnType.bYes, BtnType.bNo });
What I would like to accomplish is the following and I cannot find a solution.
public enum BtnType { bOK = { Name = "OKBtn", Text = "OK" },
bCancel = {},
bYes = {},
bNo = {} };
public static void SetButtons(BtnType[] _btnType, string onClick)
{
foreach (int i in _btnType)
{
btnp.Name = _btnType[i].Name;
btnp.Text = _btnType[i].Text;
}
}
Thank you.
foreachyou won't get index but aBtnTypeobject.