Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
4
Answers
System.IndexOutOfRangeException
tan shen
7y
138
1
Reply
I running the program but come out this error. I cannot find how to fix it, can anyone help me?
int
counter = 0;
int
select;
public
Form1()
{
InitializeComponent();
}
private
void
TeachingPage()
{
lblTitle.Visible =
false
;
btnAnimal.Visible =
false
;
btnFlower.Visible =
false
;
btnInsect.Visible =
false
;
btnStationery.Visible =
false
;
btnShape.Visible =
false
;
btnColour.Visible =
false
;
btnFruit.Visible =
false
;
btnVehicle.Visible =
false
;
lblFileName.Visible =
true
;
pictureBox1.Visible =
true
;
}
private
void
MainPage()
{
lblTitle.Visible =
true
;
btnAnimal.Visible =
true
;
btnFlower.Visible =
true
;
btnInsect.Visible =
true
;
btnStationery.Visible =
true
;
btnShape.Visible =
true
;
btnColour.Visible =
true
;
btnFruit.Visible =
true
;
btnVehicle.Visible =
true
;
lblFileName.Visible =
false
;
pictureBox1.Visible =
false
;
counter = 0;
SpeakCancel();
timer1.Stop();
}
private
void
Speak()
{
SpeechSynthesizer s =
new
SpeechSynthesizer();
s.SelectVoiceByHints(VoiceGender.Male);
s.SpeakAsync(lblFileName.Text);
s.SpeakAsync(lblFileName.Text);
}
private
void
SpeakCancel()
{
SpeechSynthesizer s =
new
SpeechSynthesizer();
s.SelectVoiceByHints(VoiceGender.Male);
s.SpeakAsyncCancelAll();
}
private
void
btnAnimal_Click(
object
sender, EventArgs e)
{
TeachingPage();
counter++;
string
path = @
"C:\Users\Tan Wei Shen\Desktop\FYP\Animal"
;
string
[] filePaths = Directory.GetFiles(path,
"*.jpg"
);
pictureBox1.Image = Image.FromFile(filePaths[counter]);
lblFileName.Text = Path.GetFileNameWithoutExtension(filePaths[counter]);
//show name of the image
Speak();
timer1.Start();
select = 1;
}
private
void
btnInsect_Click(
object
sender, EventArgs e)
{
TeachingPage();
counter++;
string
path = @
"C:\Users\Tan Wei Shen\Desktop\FYP\Insect"
;
string
[] filePaths = Directory.GetFiles(path,
"*.jpg"
);
pictureBox1.Image = Image.FromFile(filePaths[counter]);
lblFileName.Text = Path.GetFileNameWithoutExtension(filePaths[counter]);
//show name of the image
Speak();
timer1.Start();
select = 2;
}
private
void
timer1_Tick(
object
sender, EventArgs e)
{
counter++;
if
(select == 1)
{
string
path = @
"C:\Users\Tan Wei Shen\Desktop\FYP\Animal"
;
string
[] filePaths = Directory.GetFiles(path,
"*.jpg"
);
if
(counter < filePaths.Length)
{
pictureBox1.Image = Image.FromFile(filePaths[counter]);
lblFileName.Text = Path.GetFileNameWithoutExtension(filePaths[counter]);
Speak();
}
else
{
MainPage();
}
}
else
if
(select == 2)
{
string
path = @
"C:\Users\Tan Wei Shen\Desktop\FYP\Insect"
;
string
[] filePaths = Directory.GetFiles(path,
"*.jpg"
);
if
(counter < filePaths.Length)
{
pictureBox1.Image = Image.FromFile(filePaths[counter]);
lblFileName.Text = Path.GetFileNameWithoutExtension(filePaths[counter]);
Speak();
}
else
{
MainPage();
}
}
}
}
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
Unable to show Highcharts graph - ASP.Net MVC
The type initializer for 'spr840' threw an exception in C#