Context is I am making a small app for our NBA fantasy draft using c# windows forms.
I am trying to make a button click set text to a label then wait before selecting the random item from the listbox. It seems that clicking the button doesn't do anything unless it is able to complete in its entirety. So Sleep doesn't work. Is there some way I can implement a delay between changing the label text and selecting the random item from the listbox and displaying it in the other listbox?
Hopefully that makes sense. Thanks in advance!
Here is my code:
private void button2_Click(object sender, EventArgs e)
{
string order;
if (draftClicked == false && isLast == false)
{
order = "first";
draftClicked = true;
}
else if (draftClicked == true && isLast == false)
{
order = "next";
isLast = true;
}
else
{
order = "final";
}
label4.Text = "With the " + order + " pick in the 2022/23 \r\n Fantasy Season we have...";
ListBox.ObjectCollection list = listBox1.Items;
Random rng = new Random();
int n = list.Count;
if (n > 0)
{
int k = rng.Next(n);
listBox2.Items.Add(list[k]);
listBox1.Items.Remove(list[k]);
}
}