I have a menu, where a user selects one out of 4, and another 2 or 4 options will appear. I used big buttons; a picturebox + label to create the buttons.
The 4 main buttons are fixed, but the 4 other buttons depend on the first choice. Text and image will change. I programmed this, but I kinda feel this must be possible more easily.
I have 4 structs which contain the image path and label text. like this: (I'll only show with 2, because the rest won't add anything, it is just the same.)
private const string _mainButton1 = "ConfigDP";
private const string _mainButton2 = "ConfigADP";
struct ConfigDPSubmenu
{
public const string _SubMenuBtn1Text = "text submenu 1 button 1";
public const string _SubMenuBtn2Text = "text submenu 1 button 2";
public const string _SubMenuBtn1Img = "DevPortal.png";
public const string _SubMenuBtn2Img = "CustomDevPortal.png";
}
struct ConfigADPSubmenu
{
public const string _SubMenuBtn1Text = "text submenu 2 button 1";
public const string _SubMenuBtn2Text = "text submenu 2 button 2";
public const string _SubMenuBtn1Img = "ADP.png";
public const string _SubMenuBtn2Img = "CustomADP.png";
}
Then I have the function where I make the buttons: (it is called when press on the main buttons)
private void CreateSubButtons(string sender)
{
pictureBoxSubBtn3.Image = null;
pictureBoxSubBtn4.Image = null;
SubBtn3Text.Text = "";
SubBtn4Text.Text = "";
panelSubBtn3.BorderStyle = BorderStyle.None;
panelSubBtn4.BorderStyle = BorderStyle.None;
switch (sender)
{
case _mainButton1:
SubBtn1Text.Text = ConfigDPSubmenu._SubMenuBtn1Text;
SubBtn2Text.Text = ConfigDPSubmenu._SubMenuBtn2Text;
pictureBoxSubBtn1.Image = Image.FromFile(ConfigDPSubmenu._SubMenuBtn1Img);
pictureBoxSubBtn2.Image = Image.FromFile(ConfigDPSubmenu._SubMenuBtn2Img);
panelSubBtn1.BorderStyle = BorderStyle.FixedSingle;
panelSubBtn2.BorderStyle = BorderStyle.FixedSingle;
break;
case _mainButton2:
SubBtn1Text.Text = ConfigADPSubmenu._SubMenuBtn1Text;
SubBtn2Text.Text = ConfigADPSubmenu._SubMenuBtn2Text;
pictureBoxSubBtn1.Image = Image.FromFile(ConfigADPSubmenu._SubMenuBtn1Img);
pictureBoxSubBtn2.Image = Image.FromFile(ConfigADPSubmenu._SubMenuBtn2Img);
panelSubBtn1.BorderStyle = BorderStyle.FixedSingle;
panelSubBtn2.BorderStyle = BorderStyle.FixedSingle;
break;
}
}