Tryng to work on a program to make a menu on form1. What it will do is display the different things offered at the restaurant and the text will scrolll from the bottom of the screen to the top and then repeat.

I was able to figure out how to make labels dynamically but I can't figure out how to display them on form1.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cafeteka_mod1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int fav = 9;

        void allamerican()
        {
            Label[] labels = new Label[fav];

            for(int i = 0; i < fav; i++)
            {
                labels[i] = new Label();
            }
            for(int a = 0; a < fav; a++)
            {
                this.Controls.Add(labels[a]);
            }
            string[] one = { "ALL AMERICAN FAVOURITES","Cafe Americano... $35",
            "Capuccino... $40",
            "Cafe Latta... $40",
            "Macchiato... $50",
            "Mocha... $40",
            "Mocha Blanco... $50",
            "Espresso... $30",
            "Mocha Organico... $60",
            "Cold Brew... $50"};

            for(int y = 0; y < fav; y++)
            {
                labels.Text = one.ToString();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }
    }
}

Recommended Answers

Your method allamerican() is never called.

Jump to Post

All 3 Replies

I did what you suggested and nothing appears. When I run through the lines of code I have a red line below line 45 Text.

What I am trying to do here is dynamicaly create the number of labels needed to display the string elements in the list and then display them in form1. How do I do that and am I on the right track?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.