Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8730279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:59:21+00:00 2026-06-13T08:59:21+00:00

I am creating a menu with big buttons containing an image, and text. When

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:59:22+00:00Added an answer on June 13, 2026 at 8:59 am

    Create a class to hold the button text, image name and border styles – say ButtonData.

    Create several lists (or arrays) of ButtonData, one per menu.

    You can then iterate over the lists and extract the data.

    public class ButtonData
    {
       public ButtonData(string text, string image, BorderStyle border)
       {
           Text = text;
           Image = image;
           Border = border;
       }
    
       public string Text { get; private set; }
       public string Image { get; private set; }
       public BorderStyle Border { get; private set; }
    }
    
    var devMenuData = new List<ButtonData> { 
                                      new ButtonData("", null, "Borderstyle.None"), 
                                      new ButtonData("text submenu 3 button 1",
                                                     "Settings.png",
                                                     Borderstyle.FixedSingle), 
                                      ...
                                           };
    

    Your function would something like:

    private void CreateButtons(IEnumerable<ButtonData> data)
    {
        foreach (var buttonData in data)
        {
            SubBtnText[i].Text = buttonData.Text;
            pictureBoxSubBtn[i].Image = Image.FromFile(buttonData.Image);
            panelSubBtn[i].BorderStyle = buttonData.Border;
        }
    }
    

    The above amended function will not work as such, as .NET doesn’t have control arrays. You could create another list/array to iterate over or index through for this to work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a site with lots of big scrollable text-boxes in it. Each
I'm creating a menu and I want the buttons to pop I guess on
I am creating menu in joomla (do not worry if you not know joomla
I am creating a menu bar where I need to show border on hover.
I am creating a popup menu with jQuery with some buttons. Number of buttons
I am creating an menu and having problem to access the element to hide
I am creating a menu and assigning images to menu items, sometime first item
I am creating a menu system using a UL/LI structure. I'm trying to use
I'm creating several menu items programmatically like this : NSMenuItem* newItem = [[NSMenuItem alloc]
I am creating a Menu test for my restaurant as a project and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.