Problem with KeyUp and arrows

I have one problem. I want to use the right and left arrows to scroll through the images, and I did it perfectly. The right arrow goes forward and the left arrow goes backward. And when I press the right arrow, then it's like pressing the left arrow, and again when I press the right arrow again, only then do the pictures scroll, and so every time, so I have to double-click the right arrow to scroll through the pictures, so does the left. Mostly you will notice that when I click the arrow, that "button" is in blue which means like I pressed it but I didn't.
Here is the video: 668392526
private void nxt_KeyUp(object sender, KeyEventArgs e)///Next image
{
if(e.KeyCode == Keys.Right)
{
try
{
next++;
slike.Image = listaSlika.Images[next];
}
catch (Exception ex)
{
MessageBox.Show("Nema vise opcija za naprijed!");
}
if (next > 3)
{
next = 3;
}
}
}
private void prev_KeyUp(object sender, KeyEventArgs e)//Previous image
{
if (e.KeyCode == Keys.Left)
{
try
{
next--;
slike.Image = listaSlika.Images[next];
}
catch (Exception ex)
{
MessageBox.Show("Ne mozes nazad!");
}
if (next < 0)
{
next = -1;
}
}
}
Yes, without code, difficult to guess the problem...
Otherwise, there is the built-in control FlipView
Test with WinUI 3 :
@Karen Payne MVP @Castorix31 I'm sorry, i fogert add code. I edited this question. Please look at up.
@Castorix31 I know, but I'm new to C # so I want to practice, I looked for a solution on the internet but I saw that something needed to be added to the method, but I still don't know what it should be, and how to check that if I press the left arrow forward, so I did it myself.
@Sanel Pandzic , which control you are using about nxt and prev? Is it a command button control?
@Jack J Jun Yes, this code is in the button
Sign in to comment
1 answer
Sort by: Most helpful
@Jack J Jun @Castorix31 @Rool0507
Now I put the code under the switch, and I merged these two buttons into one event and still have
I still have a problem with the button, when I press the left arrow the first time, it looks like I clicked the right button, but I didn't, and the second time I press the left click, then it's fine, but that's how it goes. So I just have one more problem left, you can see it better in the video.
This may not be related, but did you mean to set
next
to 0 here instead of -1:Also inside your
switch
/case
instead of incrementing/decrementingnext
potentially out of bounds of the array & hitting aArgumentOutOfRangeException
and then fixing the out-of-range index, you could just check it before hand:Sign in to comment