TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
tan shen
NA
11
1.9k
System.IndexOutOfRangeException
Nov 2 2017 10:53 PM
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();
}
}
}
}
Reply
Answers (
4
)
Unable to show Highcharts graph - ASP.Net MVC
The type initializer for 'spr840' threw an exception in C#