Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello! So, I use a picturebox, textbox and 2 buttons for change items. Almost everything working fine:::
C#
private void buttonPicNext_Click(object sender, EventArgs e)
        {
            if (pic == pictures.Length - 1 && txt == text.Length - 1) 
               { buttonPicNext.Enabled = false; }
            else 
               { buttonPicBack.Enabled = true; pic++; txt++; }

            pictureBox1.Image = Image.FromFile("images/Word/" + pictures[pic]);
            textBox1.Text = text[txt];
        }

Pictures and texts are in array.
This one button give ++ both, because picture and text are couple.
// The other [--] button has no problem.

Well, for example I have 5 pictures/texts. When I reach the last item (5th) I have one more click which disable this button and this click designate the whole last (5th) text.
[Textbox:: ImeMode:NoControl, MultiLine:True, ReadOnly:True +vertical scrollbar]

If Textbox / Behavior / Enabled is false, it's ok, but text is grey and hard to read.

Are there other solutions to avoid this problem?
Posted

1 solution

don't disable, do nothing if you reach last item in the list
C#
private void buttonPicNext_Click(object sender, EventArgs e){
if(pic < pictures.Length -1)
{
   pic++; txt++;
   pictureBox1.Image = Image.FromFile("images/Word/" + pictures[pic]);
   textBox1.Text = text[txt];
}
}
 
Share this answer
 
v2
Comments
Norde 10-Aug-15 14:39pm    
I disabled buttons, because didn't want to get "IndexOutOfRange...".

"if(pic <= pictures.Length -1)" - Index will going out of range, because allow to click.
Without '=' won't going out of range, at the end allow to click more, but won't happen nothing.

Thank you for solution!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900