I'm trying to get my items in my domainUpDown control to spin for a few seconds rather than just increment/decrement one item at a time and then stop randomly on any item, but not sure how to go about it. I have the Wrap property set to True so the items will loop. I'm pretty sure I'll need a timer and randomly set how long each time it will spin for. Any ideas?

Recommended Answers

All 2 Replies

Use Invoke method of domainUpDown control.

private void Form1_Load(object sender, EventArgs e)
        {
            domainUpDown1.Items.AddRange(new string[] { "A", "B", "C", "D", "E", "F", "G", "H" });
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            domainUpDown1.Invoke(new Action(() => {
                Random r = new Random();
                int n = r.Next(0, domainUpDown1.Items.Count);
                for (int i = 0; i <= n; i++)
                {
                    System.Threading.Thread.Sleep(20);
                    domainUpDown1.SelectedIndex = i;
                    domainUpDown1.Refresh();
                }
            
            }));
        }

Groovy! That works quite well for me. Thank you very much!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.