質問

I have a small program that has a flowLayoutpanel1 I am placing a number od fynamically created labels in it like so:

enter image description here

but i want these labels to have some kind of gap between each other so they are not touching and lbl.SetBounds(); does not seem to work here.

This is the code I am testing?

flowLayoutPanel1.Controls.Clear();
            int length = 9;
            for (int i = 0; i < length; i++)
            {
                Label lbl = new Label();
                lbl.Name = i.ToString();
                lbl.Text = "Label " + i.ToString();
                lbl.AutoSize = true;
                lbl.Font = new Font("Ariel", 10);
                lbl.SetBounds(0, 20, 70, 70);
                lbl.BorderStyle = BorderStyle.FixedSingle;
                flowLayoutPanel1.Controls.Add(lbl);
            }

Any suggestions on how to get the spacing done?

役に立ちましたか?

解決

if you want to increase the space between the text and the outlines use:

lbl.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);

with margin

If you want to add space between the outlines, use:

lbl.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);

with padding

or both

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top