0

I'm doing a system about voice recognition. now what i want to do is when i say "scroll up". It will do that command. I've already did the scroll down command. Here's my code sample:

if (r = "scroll down")
{
    listbox1.SelectedIndex = listbox1.Items.Count - 1;
    listbox1.SelectedIndex = -1;
}

if (r == "scroll up")
{
    //scroll up code here
}
vc 74
  • 37,131
  • 7
  • 73
  • 89
KarmaKid
  • 25
  • 2
  • Scroll up and scroll down can mean different things depending on the environment. In your case, does scroll up mean move the scrollbar up (in which case the page scrolls down) or does scroll up mean the pages moves up? In any event, if you have implemented a function and you then want to implement the opposite you would just invert the function you had already implemented. That being said, I don't think your implementation of 'scroll down' does what you think; the fact that you assign `listbox1.SelectedIndex` twice and that it's final value is always -1 are sort of a give-away. – Jason Boyd Feb 20 '18 at 08:07
  • What have you tried? A search for 'c# listbox scroll' should give plenty of answers: https://stackoverflow.com/questions/8796747/how-to-scroll-to-bottom-of-listbox – gtalarico Feb 20 '18 at 08:08

1 Answers1

0

You can use:

if (listbox1.Items.Count > 0)
    listbox1.ScrollIntoView(listbox1.Items[0]);

this will scroll the first item into view.

Marc
  • 179
  • 1
  • 7