Search code examples
groupbox

Add labels dynamically on Groupbox but only half text is displaying


I am trying to add dynamic labels on groupbox, but my text size which I also created dynamically is only showing half of it on group box.

This is my simple code:

private void AddLabels()

     {
         List<Label> labels = new List<Label>();

         groupBox1.Controls.Clear();
         Label l = new Label();
         l.Font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Serif), 30, FontStyle.Bold);
         l.Text = "Hello World";
         l.Parent = groupBox1;
         l.BringToFront();
         labels.Add(l);

     }

As you notice on my code, my Font Size is 30, but when I run this, only "Hello" text is showing and only half of "Hello" is showing. The word "World" is not showing also.


Solution

  • Just in case you encounter the same problem. I already figured it the day I posted my question and I want to answer this just in case someone is looking for an answer.

    Just adjust your label font size and everything will work fine.