如何使用C#生成Dynamicaly行和列,就像在Windows中的表一样 [英] How generate Dynamicaly rows and columns like a table in windows using C#

查看:53
本文介绍了如何使用C#生成Dynamicaly行和列,就像在Windows中的表一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码



This is my Code

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private List<textbox> inputTextBoxes;
        public Form1()
        {
            InitializeComponent();
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            this.AutoSize = true;
            this.Padding = new Padding(0, 0, 20, 20);
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            int inputNumber = Int32.Parse(textBox1.Text);
            inputTextBoxes = new List<textbox>();
            inputTextBoxes = new List<textbox>();

            for (int i = 1; i <= inputNumber; i++)
            {
                Label labelInput = new Label();
                TextBox textBoxNewInput = new TextBox();
                labelInput.Text = " " + i;
                labelInput.Location = new Point(30, textBox1.Bottom + (i * 30));
                labelInput.AutoSize = true;
                textBoxNewInput.Location = new Point(labelInput.Width, labelInput.Top - 3);
                inputTextBoxes.Add(textBoxNewInput);
                this.Controls.Add(labelInput);
                this.Controls.Add(textBoxNewInput);
           }
          
        }
       
    }



但我想要三列标题,如S.No,Name ,目标和行基于在文本框中输入的值


But i want Three column Heading like S.No,Name,Destination and rows based on the value entered in the text box

推荐答案

然后您可能需要创建固定宽度标签并将它们放置在表单的顶部。然后,对于每一行,在标签下方的相对点处添加三个文本框。或者你可以让自己轻松生活并使用 DataGridView [ ^ ]。
Then you probably need to create fixed width labels and position them at the top of the form. Then for each row you add the three textboxes at the relative points below the labels. Or you could make life easy for yourself and use a DataGridView[^].


这篇关于如何使用C#生成Dynamicaly行和列,就像在Windows中的表一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆