I am creating a menu with big buttons containing an image, and text. When selected a border is around the button.
The button text is not always the same, and the result of the button click neither.
I have the image name, and text per button set in a struct like this: (there are four of them, but i'll show 2)
struct ConfigDevSubmenu
{
public const string SubMenuBtnText1 = "";
public const string SubMenuBtnText2 = "text submenu 3 button 1";
public const string SubMenuBtnText3 = "text submenu 3 button 2";
public const string SubMenuBtnText4 = "";
public const string SubMenuBtnImg1 = null;
public const string SubMenuBtnImg2 = "Settings.png";
public const string SubMenuBtnImg3 = "LoadFirmware.png";
public const string SubMenuBtnImg4 = null;
public const string SubMenuBtnBorder1 = "Borderstyle.None";
public const string SubMenuBtnBorder2 = "Borderstyle.FixedSingle";
public const string SubMenuBtnBorder3 = "Borderstyle.FixedSingle";
public const string SubMenuBtnBorder4 = "Borderstyle.None";
}
struct AdvancedSubmenu
{
public const string SubMenuBtnText1 = "text submenu 4 button 1";
public const string SubMenuBtnText2 = "text submenu 4 button 2";
public const string SubMenuBtnText3 = "text submenu 4 button 3";
public const string SubMenuBtnText4 = "text submenu 4 button 4";
public const string SubMenuBtnImg1 = "GenerateEncKey.png";
public const string SubMenuBtnImg2 = "Monitoring.png";
public const string SubMenuBtnImg3 = "AdvancedSettings.png";
public const string SubMenuBtnImg4 = "GenerateConfigFile.png";
public const string SubMenuBtnBorder1 = "Borderstyle.FixedSingle";
public const string SubMenuBtnBorder2 = "Borderstyle.FixedSingle";
public const string SubMenuBtnBorder3 = "Borderstyle.FixedSingle";
public const string SubMenuBtnBorder4 = "Borderstyle.FixedSingle";
}
I do not think this can be done much easier without using database files.
To create the buttons I have this function which has as argument the which struct it should use, and in a switch case structure each button is created. But I've found myself copy-pasting alot in these functions so this must be possible easier. Therefore I tried something like below, but that does not work. I'd like to know whether it is possible to make that work, and how I should do that.
private void createButtons(string Struct)
{
for (int i = 1; i < 5; i++)
{
SubBtnText[i].Text = Struct.SubMenuBtnText[i];
pictureBoxSubBtn[i].Image = Image.FromFile(Struct.SubMenuBtnImg[i]);
panelSubBtn[i].BorderStyle = Struct.SubMenuBtnBorder[i];
}
}
Any suggetions?