-
-
Save zivanovicb/d752e32e2e4b0567b962e7412692f760 to your computer and use it in GitHub Desktop.
ImageList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace WindowsFormsApplication20 | |
{ | |
public partial class Form1 : Form | |
{ | |
// brojac koji zna koja slika se trenutno prikazuje | |
int curr = 0; | |
ImageList lista = new ImageList(); | |
Random r = new Random(); | |
public Form1() | |
{ | |
InitializeComponent(); | |
// Ubaci neke slike u C:\Users\beki\Documents\Visual Studio 2015\Projects\WindowsFormsApplication20\WindowsFormsApplication20\bin\Debug | |
// i onda ih dodaj ovde u kodu | |
lista.Images.Add(Image.FromFile("ok.jpg")); | |
lista.Images.Add(Image.FromFile("fc.jpg")); | |
lista.Images.Add(Image.FromFile("edu.jpg")); | |
// Namesti u properties size mode na StretchImage | |
pictureBox1.Image = lista.Images[curr]; | |
} | |
private void button1_Click(object sender, EventArgs e) // Prebacuje na sledecu | |
{ | |
curr++; // Uvecavas brojac | |
if(curr == lista.Images.Count) | |
{ | |
// Ako brojac predje broj slika vraca se na 0. Ako ti nije jasno zasto se ovo desava obrisi kod i pokreni program i skapiraces. | |
curr = 0; | |
} | |
pictureBox1.Image = lista.Images[curr]; | |
} | |
private void button2_Click(object sender, EventArgs e) | |
{ | |
curr--; // Umanjujes brojac | |
if (curr < 0) | |
{ | |
// Ako brojac ide ispod 0 vracamo ga na poslednji element u listi. | |
// Obrisi ako ne kapiras pa isprobaj | |
curr = lista.Images.Count - 1; | |
} | |
pictureBox1.Image = lista.Images[curr]; | |
} | |
private void button3_Click(object sender, EventArgs e) | |
{ | |
curr = r.Next(0,lista.Images.Count); | |
pictureBox1.Image = lista.Images[curr]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment