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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Aug 17, 2009, 1:50 PM
+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
MaharajePosted Aug 17, 2009, 9:14 PM
Honesty Pays
Good Luck
MaharajePosted Aug 17, 2009, 10:11 AM
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)
Kirtan PatelPosted Aug 17, 2009, 9:47 AM
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 :)
MaharajePosted Aug 17, 2009, 9:27 AM
Now i want to add something else to this project and it is a slideshow, how it works?
Thank you
Kirtan PatelPosted Aug 17, 2009, 9:12 AM
if (finfo.Extension == ".jpg" || finfo.Extension == ".gif")
to
if (finfo.Extension == ".jpg" || finfo.Extension == ".gif" || finfo.Extenstion == ".jpeg" || finfo.Extenstion == ".png")
MaharajePosted Aug 17, 2009, 9:07 AM
No i selected some .jpg pictures and immedately this exception happen PLZ Help me
Thank you so much for your help
Kirtan PatelPosted Aug 17, 2009, 6:46 AM
MaharajePosted Aug 16, 2009, 9:16 PM
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 PatelPosted Aug 16, 2009, 4:26 PM
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;
}
}
MaharajePosted Aug 16, 2009, 12:44 PM
i want it in C#.Net GUI
i test the link but it don't open
Thanks