Marina K
asked on
how can i make a previous button here?
So i am making a game in visual c#...the first stage is looking through the photos that are shown in a picturebox. I have written this code so far:
namespace FaceNameGame
{
public partial class LevelOnePartOne : Form
{
int m , piccount=0, k;
Random rd = new Random();
public string[] picturenames= new string[4];
public string[] links = new string[3];
string sourcePath = @"C:\Users\Marina\Desktop\ FaceNameGa me\images" ;
string targetPath = @"C:\Users\Marina\Desktop\ FaceNameGa me\images\ used";
bool directoryexists = false;
string[] files = Directory.GetFiles(@"C:\Us ers\Marina \Desktop\F aceNameGam e\images\" , "*.jpg", SearchOption.AllDirectorie s);
public LevelOnePartOne()
{
InitializeComponent();
}
private void LevelOnePartOne_Load(objec t sender, EventArgs e)
{
ProceedBtn.Hide();
PreviousBtn.Hide();
if (!System.IO.Directory.Exis ts(targetP ath))
{
System.IO.Directory.Create Directory( targetPath );
directoryexists = true;
}
Random rand = new Random();
string[] files = Directory.GetFiles(@"C:\Us ers\Marina \Desktop\F aceNameGam e\images\" , "*.jpg", SearchOption.AllDirectorie s);
for (m = 0; m < 3; m++)
{
Loop:
picturenames[m] = files[rand.Next(files.Leng th)];
string name1 = picturenames[m].ToString() ;
string name2 = name1.Substring(name1.Last IndexOf("\ \"));
string name3 = name2.Remove(name2.Length - 4, 4);
string name = name3.Remove(0, 1);
string filename = name2.TrimStart('\\');
if (!IsDirectoryEmpty(targetP ath))
{
if (File.Exists("C:\\Users\\M arina\\Des ktop\\Face NameGame\\ images\\us ed\\" + filename))
{
goto Loop;
}
}
string sourceFile = System.IO.Path.Combine(sou rcePath, filename);
string destFile = System.IO.Path.Combine(tar getPath, filename);
System.IO.File.Copy(source File, destFile, true);
}
ShowCurrentImage(0);
k = 1;
}
private void NextBtn_Click(object sender, EventArgs e)
{
piccount++;
if(piccount < 3)
{
if (k<3)
{
ShowCurrentImage(k);
k++;
}
}
if (piccount == 2)
{
NextBtn.Hide();
ProceedBtn.Show();
}
if (k > 0)
{
PreviousBtn.Show();
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void PhotoTemplatePicBx_Click(o bject sender, EventArgs e)
{
}
private void ProceedBtn_Click(object sender, EventArgs e)
{
LevelOnePartTwo lvltwoprttwo = new LevelOnePartTwo();
this.Hide();
lvltwoprttwo.Show();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Escape)
{
this.Close();
if (directoryexists)
{
Directory.Delete(targetPat h, true);
}
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void PreviousBtn_Click(object sender, EventArgs e)
{
if (k > 0 && k < 3)
{
ShowCurrentImage(k);
k--;
}
}
protected void ShowCurrentImage(int picindex)
{
string[] filestouse = Directory.GetFiles(@"C:\Us ers\Marina \Desktop\F aceNameGam e\images\u sed\", "*.jpg", SearchOption.AllDirectorie s);
pictureBox1.Load(filestous e[picindex ]);
string nameused1 = pictureBox1.ImageLocation. ToString() ;
string nameused2 = nameused1.Substring(nameus ed1.LastIn dexOf("\\" ));
string nameused3 = nameused2.Remove(nameused2 .Length - 4, 4);
string nameused = nameused3.Remove(0, 1);
namelbl.Text = "Hello,my name is" + " " + nameused;
}
public bool IsDirectoryEmpty(string path)
{
string[] dirs = Directory.GetDirectories(p ath); string[] files = System.IO.Directory.GetFil es(path);
return dirs.Length == 0 && files.Length == 0;
}
}
}
everything works fine except the previous button...any ideas on how i can do it? Thanks in advance for you help...
namespace FaceNameGame
{
public partial class LevelOnePartOne : Form
{
int m , piccount=0, k;
Random rd = new Random();
public string[] picturenames= new string[4];
public string[] links = new string[3];
string sourcePath = @"C:\Users\Marina\Desktop\
string targetPath = @"C:\Users\Marina\Desktop\
bool directoryexists = false;
string[] files = Directory.GetFiles(@"C:\Us
public LevelOnePartOne()
{
InitializeComponent();
}
private void LevelOnePartOne_Load(objec
{
ProceedBtn.Hide();
PreviousBtn.Hide();
if (!System.IO.Directory.Exis
{
System.IO.Directory.Create
directoryexists = true;
}
Random rand = new Random();
string[] files = Directory.GetFiles(@"C:\Us
for (m = 0; m < 3; m++)
{
Loop:
picturenames[m] = files[rand.Next(files.Leng
string name1 = picturenames[m].ToString()
string name2 = name1.Substring(name1.Last
string name3 = name2.Remove(name2.Length - 4, 4);
string name = name3.Remove(0, 1);
string filename = name2.TrimStart('\\');
if (!IsDirectoryEmpty(targetP
{
if (File.Exists("C:\\Users\\M
{
goto Loop;
}
}
string sourceFile = System.IO.Path.Combine(sou
string destFile = System.IO.Path.Combine(tar
System.IO.File.Copy(source
}
ShowCurrentImage(0);
k = 1;
}
private void NextBtn_Click(object sender, EventArgs e)
{
piccount++;
if(piccount < 3)
{
if (k<3)
{
ShowCurrentImage(k);
k++;
}
}
if (piccount == 2)
{
NextBtn.Hide();
ProceedBtn.Show();
}
if (k > 0)
{
PreviousBtn.Show();
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void PhotoTemplatePicBx_Click(o
{
}
private void ProceedBtn_Click(object sender, EventArgs e)
{
LevelOnePartTwo lvltwoprttwo = new LevelOnePartTwo();
this.Hide();
lvltwoprttwo.Show();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Escape)
{
this.Close();
if (directoryexists)
{
Directory.Delete(targetPat
}
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void PreviousBtn_Click(object sender, EventArgs e)
{
if (k > 0 && k < 3)
{
ShowCurrentImage(k);
k--;
}
}
protected void ShowCurrentImage(int picindex)
{
string[] filestouse = Directory.GetFiles(@"C:\Us
pictureBox1.Load(filestous
string nameused1 = pictureBox1.ImageLocation.
string nameused2 = nameused1.Substring(nameus
string nameused3 = nameused2.Remove(nameused2
string nameused = nameused3.Remove(0, 1);
namelbl.Text = "Hello,my name is" + " " + nameused;
}
public bool IsDirectoryEmpty(string path)
{
string[] dirs = Directory.GetDirectories(p
return dirs.Length == 0 && files.Length == 0;
}
}
}
everything works fine except the previous button...any ideas on how i can do it? Thanks in advance for you help...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured it out now. This answer helped me very much. Thank you
Hope you might got some help from my answer!!