Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Visual C# 2010:How to add create new Labels or Buttons in Runtime with an incremented integer at the end?

$
0
0

Hello,

First of all, I am an amateur programmer.

You know how the C# environment automatically names the first button you drag into the form as button1? Then when you drag another, it names it button2. I am not talking about the text, but the NAME. So this has no specified limit. My question is, how do I do that from the program? So each time I click a button, a new button should be created. If I click the button 5 times, 5 buttons should be created. As each one needs a unique name, an incrementing integer at the end would be perfect, like this:

namespace Duplicate
    {
    public partial class Form1 : Form
        {
        int c = 1;
        public Form1()
            {
            InitializeComponent();
            }

        private void button1_Click(object sender, EventArgs e)
            {
            c++;
///Of course, this does not work:
            Button "button"+ c = new Button();
            }
        }
    }

Can we do something like that, at least something quite near?

Thanks in advance,

Aadi B.




Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>