Hi, I have a flowLayoutPanel, into which I want to add new labels when the user clicks on a button. Is this possible? C#, Winforms, Visual Studio
I am trying something like this:

//inside click event handler
string submitWord = tempWord;
Label lbl = new Label();
lbl.Text = submitword;
flowLayoutPanel.Controls.Add(lbl);

Thanks

Recommended Answers

All 2 Replies

YOu have to set some more parameters, like position (Location), size (if necessary), name, ...:

//inside click event handler
string submitWord = tempWord;
Label lbl = new Label();
lbl.Name ="label1";
lbl.Text = submitword;
lbl.Location = (20, 20); //set your location
lbl.AutoSize = true;
flowLayoutPanel.Controls.Add(lbl);

sorry if I wasted anybody's time. turns out the label was there, but the label I used was one with black ForeColor, which looks invisible on a black background. this silly thing kept me busy for 30 minutes: debugging, setting watches and all. turns out I should name the controls I create a bit more descriptively! Lesson learnt!

Be a part of the DaniWeb community

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