简体   繁体   中英

How to Add From TextBoxes To panel in C#

Designed a to-do list UI/UX in c#. At the moment I can only add one item to the panel when I try to add another item it doesn't get added to the panel.

在此处输入图像描述

 public void addItems(string text) 
    {
        ToDoItem item = new TO_DO_LIST.ToDoItem(text);
        listBox1.Controls.Add(item);

        //ToDoItem[] todoItems = new ToDoItem[999];
        //listBox1.Items.Add(textbox.Text);

    }

    private void gunaAdvenceButton1_Click(object sender, EventArgs e)
    {
        string tarName = textbox.Text;
        addItems(tarName);

            //addToDoList(tarName);
    }

I have tried an if or else statement and a for loop, for some reason that for loop makes the application run slow don't know if I missing something or something needs to be added

You're adding user controls to the listbox. The next items are added, it's just that they're all in the same position: (0;0).

You need to put each control beneath the previous, something like:

item.Top = listBox1.Controls.Length * item.Height;

Also, put them in a panel instead, I don't think the ListBox will start showing a scrollbar if you put more controls in it than it can display. Or if it's already a panel, rename listBox1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM