dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersChandra
premkumar
Ranjith Kumar
lily
Ultimaterengan
Pawan Awasthi
SonyMadhu
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » Winforms Controls

How to show images from folder into Picture box?


Posted Date:     Category: Winforms Controls    
Author: Member Level: Diamond    Points: 30


In this article I am going to explain about how to show all images from a specified folder with previous and next button in windows application. Here I have stored lots of pictures in the folder user view all images in the picture box.



 


Description :


I have stored lots of pictures in the folder user view all images in the picture box . Providing Previous and Next options to see previous and Next images in the same folder.

Design side


I have design the form with two buttons Previous and Next look like below
image

Server side



using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
ArrayList alist = new ArrayList();
int i = 0;
int filecount = 0;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//Specify Source folder path here
System.IO.DirectoryInfo inputDir = new System.IO.DirectoryInfo("D:\\images");
try
{
if ((inputDir.Exists))
{

//Get Each jpg files from a source folder and stored in the arraylist
System.IO.FileInfo file = null;
foreach (System.IO.FileInfo eachfile in inputDir.GetFiles())
{
file = eachfile;
if (file.Extension.ToLower() == ".jpg")
{
alist.Add(file.FullName);
//Store file count here
filecount = filecount + 1;
}
}
//Initally show first image in the picture box
pictureBox1.Image = Image.FromFile(alist[0].ToString()); ;
i = 0;
}
}
catch (Exception ex)
{

}
}

private void btnNext_Click(object sender, EventArgs e)
{
//check next postion image is have or not
if (i + 1 < filecount)
{
pictureBox1.Image = Image.FromFile(alist[i + 1].ToString()) ;
i = i + 1;
}
}

private void btnPrevious_Click(object sender, EventArgs e)
{
//check previous postion image is have or not
if (i - 1 >= 0)
{
pictureBox1.Image = Image.FromFile(alist[i-1].ToString()) ;
i = i - 1 ;
}
}

}
}

Output :


image

Source code:


Client Side: Form Design
Code Behind: C#

Conclusion

I hope this code snippet is help you to know about Display image from folder in picture box.

Attachments
  • Display_Images_Source (43968-192356-Display-Images-Source.rar)





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "How to show images from folder into Picture box?"

    No responses found. Be the first to respond...

    Feedbacks      

    Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to Edit / Delete Data using Datagridview in .NET?
    Previous Resource: How to load dataset tables in treenode?
    Return to Resources
    Post New Resource
    Category: Winforms Controls


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Display image from folder  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.