本文介绍了如何在Panel中添加TextBoxes没有空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想以下列方式在Panel中添加TextBoxes

Hi All,
I wants to add TextBoxes in Panel in following way

int startPos = 0;
        int srno = 1;
        private void button2_Click(object sender, EventArgs e)
        {
            TextBox tb = new TextBox();
            tb.Location = new Point(0, startPos);
            tb.Text = srno.ToString(); srno += 1;
            panel1.Controls.Add(tb);
            startPos += tb.Height;
        }





panel1.AutoScroll = true;



前10个TextBoxes添加没有问题,但在文本框之间的一些空间左边。我不知道为什么会这样?

请帮帮我。



panel1.AutoScroll=true;

first 10 TextBoxes added fine with no problem, but after that some space lefts between textboxes. I don't Know why this happens?
Please Help me.

推荐答案

AutoScroll = True
FlowDirection = TopDown
WrapContents = False



int srno = 1;

private void button2_Click(object sender, EventArgs e)
{
    TextBox tb = new TextBox();
    tb.BorderStyle = BorderStyle.None;
    tb.Margin = new Padding(0);
    tb.Padding = new Padding(0);
    tb.Dock = DockStyle.Top;
    tb.Text = srno.ToString();

    tb.BackColor = (srno % 2 == 0) ? Color.LightBlue : Color.AliceBlue;
    
    srno ++;
    
    panel1.Controls.Add(tb);
    tb.BringToFront();
}

调整上面的不同参数以品尝。

Adjust the different parameters above to taste.


这篇关于如何在Panel中添加TextBoxes没有空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 10:33