Bu yayınımızda picturebox nesnesi ile timer kullanarak slayt
gösterisi yapmayı göreceğiz.
Bu uygulama için formumuza iki adet button, bir adet listbox,bir
adet timer ve bir adet picturebox ekliyoruz.
Dosya
işlemleri yapacağımız için System.IO kütüphanesini kullanıyoruz. Timer
ın interval değerini 1000 olarak ayarladıktan sonra kodlarımızı yazmaya
başlayabiliriz. Resimlerimizin Picturebox içerisinde tam olarak
görüntüleyebilmek için picturebox üzerindeki çentikten Size Mode seçeneğini StretchImage seçeneğini seçiyoruz.
Uygulama kodları;
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;
using System.IO;
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;
using System.IO;
namespace
pictureboxSlaytGosterisiYapma
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_KlasorSec_Click(object sender, EventArgs e)
{
FolderBrowserDialog fd = new FolderBrowserDialog();
DialogResult tus = fd.ShowDialog();
if (tus == DialogResult.OK)
{
DirectoryInfo klasor = new DirectoryInfo(fd.SelectedPath);
FileInfo[] resimler = klasor.GetFiles();
for (int i = 0; i < resimler.Length; i++)
{
if (resimler[i].Extension == ".jpg")
{
listBox1.Items.Add(resimler[i].FullName);
}
}
}
}
private void btn_Baslat_Click(object sender, EventArgs e)
{
timer1.Start();
}
int sira;
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(listBox1.Items[sira].ToString());
sira++;
if (sira == listBox1.Items.Count)
{
sira = 0;
}
}
}
}
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_KlasorSec_Click(object sender, EventArgs e)
{
FolderBrowserDialog fd = new FolderBrowserDialog();
DialogResult tus = fd.ShowDialog();
if (tus == DialogResult.OK)
{
DirectoryInfo klasor = new DirectoryInfo(fd.SelectedPath);
FileInfo[] resimler = klasor.GetFiles();
for (int i = 0; i < resimler.Length; i++)
{
if (resimler[i].Extension == ".jpg")
{
listBox1.Items.Add(resimler[i].FullName);
}
}
}
}
private void btn_Baslat_Click(object sender, EventArgs e)
{
timer1.Start();
}
int sira;
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(listBox1.Items[sira].ToString());
sira++;
if (sira == listBox1.Items.Count)
{
sira = 0;
}
}
}
}
Hiç yorum yok:
Yorum Gönder