Hi
How add some pictures with openDialogBox and navigate the pictures to next and previous?
how i can zoom them but not my picturebox become big it scrolls and only my pic big?
Thank you
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 17, 2009, 9:50 AM EDT
+It Will change Picture Every 5 Second ( this is What you call SlidShow )
+If you Click Next It Will Show next Picture and Previous if Previous
+ It Will Zoom Image and Will Show Scroll bar also to Scroll the Image
+ Zooming Functionality
I have Included Project Files Also If you Not Understand the Code Correctly then you can use them :)
Download Link is at bottom of Post
namespace PictureBox
{
public partial class Form1 : Form
{
List<string> imageList;
int CurrentPosition = 0;
public Form1()
{
InitializeComponent();
}
private void btnNext_Click(object sender, EventArgs e)
{
if (CurrentPosition < imageList.Count-1)
{
CurrentPosition += 1;
}
pictureBox1.ImageLocation = imageList[CurrentPosition];
}
private void btnPrevious_Click(object sender, EventArgs e)
{
if (CurrentPosition >0)
{
CurrentPosition -= 1;
}
pictureBox1.ImageLocation = imageList[CurrentPosition];
}
private void btnZoomPlus_Click(object sender, EventArgs e)
{
pictureBox1.Width += 20;
pictureBox1.Height += 20;
}
private void btnZoomMinus_Click(object sender, EventArgs e)
{
pictureBox1.Width -= 20;
pictureBox1.Height -= 20;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (CurrentPosition == imageList.Count - 1)
{
CurrentPosition = 0;
}
else
{
CurrentPosition++;
}
pictureBox1.ImageLocation = imageList[CurrentPosition];
}
private void btnOpenFiles_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
imageList = new List<string>();
string[] filelist = ofd.FileNames;
foreach (string file in filelist)
{
FileInfo finfo = new FileInfo(file);
if (finfo.Extension == ".jpg" || finfo.Extension == ".gif" || finfo.Extension == ".jpeg" || finfo.Extension == ".png")
{
imageList.Add(finfo.FullName);
}
}
pictureBox1.ImageLocation = imageList[CurrentPosition];
timer1.Enabled = true;
}
}
}
}
Download Project Files
Maharaje124 reputationPosted Aug 16, 2009, 8:44 AM EDT
i want it in C#.Net GUI
i test the link but it don't open
Thanks
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 16, 2009, 12:26 PM EDT
Dont Forget to mark "Do you like anwer" it will give me some credit
See the Screenshot Below
Here i have used panel and a Picture Box Put Picture Box in Panel So when size of picure change it will not go out side of panel
List<string> imageList;
int CurrentPosition = 1;
private void Form1_Load(object sender, EventArgs e)
{
imageList = new List<string>();
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
string[] filelist = ofd.FileNames;
foreach (string file in filelist)
{
FileInfo finfo = new FileInfo(file);
if (finfo.Extension == ".jpg" || finfo.Extension == ".gif")
{
imageList.Add(finfo.FullName);
}
}
pictureBox1.ImageLocation = imageList[0];
}
}
private void btnNext_Click(object sender, EventArgs e)
{
if (CurrentPosition < imageList.Count - 1)
{
pictureBox1.ImageLocation = imageList[CurrentPosition];
CurrentPosition++;
}
}
private void btnPrevious_Click(object sender, EventArgs e)
{
if (CurrentPosition != 0)
{
pictureBox1.ImageLocation = imageList[CurrentPosition];
CurrentPosition--;
}
}
private void btnZoomPlus_Click(object sender, EventArgs e)
{
pictureBox1.Width += 20;
pictureBox1.Height += 20;
}
private void btnZoomMinus_Click(object sender, EventArgs e)
{
pictureBox1.Width -= 20;
pictureBox1.Height -= 20;
}
}
Maharaje124 reputationPosted Aug 16, 2009, 5:16 PM EDT
pictureBox1.ImageLocation = imageList[0];
this is the exception: "Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 17, 2009, 2:46 AM EDT
Maharaje124 reputationPosted Aug 17, 2009, 5:07 AM EDT
No i selected some .jpg pictures and immedately this exception happen PLZ Help me
Thank you so much for your help
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 17, 2009, 5:12 AM EDT
if (finfo.Extension == ".jpg" || finfo.Extension == ".gif")
to
if (finfo.Extension == ".jpg" || finfo.Extension == ".gif" || finfo.Extenstion == ".jpeg" || finfo.Extenstion == ".png")
Maharaje124 reputationPosted Aug 17, 2009, 5:27 AM EDT
Now i want to add something else to this project and it is a slideshow, how it works?
Thank you
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 17, 2009, 5:47 AM EDT
it can Zoom Image By Just Mouse Scroll
Custom PictureBox.Dll
Right Click in ToolBox of Visual Studio >> Choose Items then Select that Dll to use
after that the Custom PictureBox Control Will be there in ToolBox after Implementing this You Dont Require those two Zoom+ and Zoom- Buttons
PictureBox That Visual Studio Provide you is Limited to its Functionality if you want this scroll type of functionality you need to develop your own Control by Inheriting that
PictureBoxClass
Happy Coding :)
Maharaje124 reputationPosted Aug 17, 2009, 6:11 AM EDT
no i found how it scrolls without developing a costomized imageBox if you true the AutoScroll of your Panel it will scroll during zooming
now i just need to know how a slide show works?(sorry ask you do you know what a slide show is? pardon me because to somebody when i asked it he didn't hear about slide show but i beleive you know it)
Maharaje124 reputationPosted Aug 17, 2009, 5:14 PM EDT
Honesty Pays
Good Luck