C
C#2y ago
Reki-

❔ Auto Slide Show

here my code
7 Replies
Reki-
Reki-OP2y ago
Reki-
Reki-OP2y ago
can you help me auto next image i don't know to use timer
namespace ImgSlideShow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<String> imagePaths = new List<String>();
int curentIndex = -1;
private void btnStart_Click(object sender, EventArgs e)
{
curentIndex = 0;
p1.ImageLocation = imagePaths[curentIndex];
}
private void Form1_Load(object sender, EventArgs e)
{
String imageFolder = Application.StartupPath + @"\images";
String[] files = System.IO.Directory.GetFiles(imageFolder);
foreach (String file in files)
{
imagePaths.Add(file);
}

if (imagePaths.Count > 0)
{
p1.ImageLocation = imagePaths[0];
curentIndex = 0;
}

}

private void btnLast_Click(object sender, EventArgs e)
{
curentIndex = imagePaths.Count - 1;
p1.ImageLocation = imagePaths[curentIndex];
}

private void btnNext_Click(object sender, EventArgs e)
{
curentIndex++;
if (curentIndex >= imagePaths.Count)
{
curentIndex = 0;
}
p1.ImageLocation = imagePaths[curentIndex];
}

private void btnPrev_Click(object sender, EventArgs e)
{
curentIndex--;
if (curentIndex < 0)
{
curentIndex = imagePaths.Count - 1;
}
p1.ImageLocation = imagePaths[curentIndex];
}

private void btnAuto_Click(object sender, EventArgs e)
{

}
private void timer1_Tick(object sender, EventArgs e)
{

}
}
}
namespace ImgSlideShow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<String> imagePaths = new List<String>();
int curentIndex = -1;
private void btnStart_Click(object sender, EventArgs e)
{
curentIndex = 0;
p1.ImageLocation = imagePaths[curentIndex];
}
private void Form1_Load(object sender, EventArgs e)
{
String imageFolder = Application.StartupPath + @"\images";
String[] files = System.IO.Directory.GetFiles(imageFolder);
foreach (String file in files)
{
imagePaths.Add(file);
}

if (imagePaths.Count > 0)
{
p1.ImageLocation = imagePaths[0];
curentIndex = 0;
}

}

private void btnLast_Click(object sender, EventArgs e)
{
curentIndex = imagePaths.Count - 1;
p1.ImageLocation = imagePaths[curentIndex];
}

private void btnNext_Click(object sender, EventArgs e)
{
curentIndex++;
if (curentIndex >= imagePaths.Count)
{
curentIndex = 0;
}
p1.ImageLocation = imagePaths[curentIndex];
}

private void btnPrev_Click(object sender, EventArgs e)
{
curentIndex--;
if (curentIndex < 0)
{
curentIndex = imagePaths.Count - 1;
}
p1.ImageLocation = imagePaths[curentIndex];
}

private void btnAuto_Click(object sender, EventArgs e)
{

}
private void timer1_Tick(object sender, EventArgs e)
{

}
}
}
TheBoxyBear
TheBoxyBear2y ago
Timer Class (System.Windows.Forms)
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.
TheBoxyBear
TheBoxyBear2y ago
Add the timer to the form through the designer or add it as a member of the form and subscribe to its Tick event In the Tick event handler, change the image of the picturebox, or since you have buttons to change the image manually, create a NextImage method that can be called from the Tick and the Next button click
Reki-
Reki-OP2y ago
@TheBoxyBear HOW TO CALLED METHOD can you write the code? @TheBoxyBear thank you so much
TheBoxyBear
TheBoxyBear2y ago
void Foo()
{
// Do stuff
}

// Inside another method
Foo();
void Foo()
{
// Do stuff
}

// Inside another method
Foo();
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server