Advertisement
tranquangchau

SoloGOAL

Jul 1st, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.IO;
  4. /*
  5.  * 2-7/2014 by @Chau
  6.  * Title SoloGoal (picture show in folder)
  7.  * IN: design 1 picturebox,1 lable
  8.  * IN: file picture +file error
  9.  * ACTION: Formload, click,close,max,minwindow
  10.  * * error
  11.  * - file type check? -> sumfile ->loadfile
  12.  * - sub file .thumail
  13.  * demo http://image.yogile.com/codecbychau/bqmjph13atql56qrlmw23s-large.jpg
  14.  * */
  15.  
  16. namespace picgoal
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.             this.TopMost = true;
  24.         }
  25.  
  26.         int i = 1; //first pic show.
  27.         int k = 0; //sum file correct. (check error)      
  28.        //picturebox click left?? right
  29.         private void pictureBox1_Click(object sender, EventArgs e)
  30.         {
  31.             label1.Hide();
  32.             if (i==findk())
  33.             {
  34.                 xaike(i, pictureBox1);
  35.                 i = 0;                                
  36.             }
  37.             else
  38.                 xaike(i, pictureBox1);
  39.                 i++;
  40.         }
  41.         //reuse function
  42.         private void xaike(int i, PictureBox pictureBox1)
  43.         {
  44.             imagenext(i, pictureBox1);
  45.             this.Text = i.ToString();
  46.         }
  47.         //find max file in folder (jpg,png,gif,JPG,PNG,GIF)
  48.         public int findk()
  49.         {
  50.             k = System.IO.Directory.GetFiles("pic", "*", SearchOption.AllDirectories).Length;            
  51.             return k;
  52.         }
  53.         //show next file
  54.         private void imagenext(int i,PictureBox pictureBoxvao)
  55.         {
  56.             pictureBoxvao.ImageLocation = checkfile(i); ;            
  57.         }
  58.  
  59.         //check file type
  60.         private string checkfile(int i)
  61.         {
  62.             string s1="pic/"+i;
  63.             if (File.Exists(s1+".jpg"))
  64.             {
  65.                 return s1 + ".jpg";
  66.             }
  67.             else
  68.                 if (File.Exists(s1 + ".png"))
  69.                 {
  70.                     return s1+".png";
  71.                 }
  72.                 else
  73.                     if (File.Exists(s1 + ".gif"))
  74.                     {
  75.                         return s1 + ".gif";
  76.                     }
  77.             return s1;//chage file picture error default
  78.         }
  79.         private void Form1_Load(object sender, EventArgs e)
  80.         {
  81.             label1.Text = findk().ToString();
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement