C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Visual Studio »

Picture box


Posted Date: 20 Oct 2009      Posted By: rooney      Member Level: Bronze     Points: 1   Responses: 2



//hello i want to show preview of an image in picture box by selecting an image from checklistbox
here is the code for adding images to checklistbox
can somebody modify the code to show the preview of image in the picture box?//

private void button3_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
DirectoryInfo FileDirectory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
//FileInfo[] FilesFromDirectory = FileDirectory.GetFiles();
FileInfo[] FileJpg = FileDirectory.GetFiles("*.jpg");
FileInfo[] FileGif = FileDirectory.GetFiles("*.gif");
FileInfo[] FileBmp = FileDirectory.GetFiles("*.bmp");
FileInfo[] FileTif = FileDirectory.GetFiles("*.tif");
FileInfo[] FilePng = FileDirectory.GetFiles("*.png");
foreach (FileInfo File in FileJpg)
{
checkedListBox1.Items.Add(File.Name);

}
foreach (FileInfo File in FileGif)
{
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileGif)
{
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileTif)
{
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FilePng)
{
checkedListBox1.Items.Add(File.Name);
}
}
}





Responses

Author: Neetu    20 Oct 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi Dear try this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace PicturePreview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
f1 = new FolderBrowserDialog();
}

FolderBrowserDialog f1;

private void button1_Click(object sender, EventArgs e)
{
if (f1.ShowDialog() == DialogResult.OK)
{
DirectoryInfo FileDirectory = new DirectoryInfo(f1.SelectedPath);
//FileInfo[] FilesFromDirectory = FileDirectory.GetFiles();
FileInfo[] FileJpg = FileDirectory.GetFiles("*.jpg");
FileInfo[] FileGif = FileDirectory.GetFiles("*.gif");
FileInfo[] FileBmp = FileDirectory.GetFiles("*.bmp");
FileInfo[] FileTif = FileDirectory.GetFiles("*.tif");
FileInfo[] FilePng = FileDirectory.GetFiles("*.png");
foreach (FileInfo File in FileJpg)
{

checkedListBox1.Items.Add(File.Name);


}
foreach (FileInfo File in FileGif)
{
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileGif)
{
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FileTif)
{
checkedListBox1.Items.Add(File.Name);
}
foreach (FileInfo File in FilePng)
{
checkedListBox1.Items.Add(File.Name);
}
}

}

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox1.ImageLocation = null;
String s = f1.SelectedPath.ToString()+ checkedListBox1.SelectedItem.ToString();
MessageBox.Show(s.ToString());
pictureBox1.ImageLocation = s;
}
}
}


regards
Neetu



Author: Anuraj    20 Oct 2009Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Try this code in the selectedIndexChanged event

PictureBox1.Image = Image.FromFile(Path.Combine(f1.SelectedPath,checkedListBox1.Items[ checkedListBox1.SelectedIndex].ToString()));


Thanks
Anuraj
THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS.
BEWARE OF BUGS IN THE ABOVE CODE; I HAVE ONLY PROVED IT CORRECT, NOT TRIED IT.
dotnetthoghts



Post Reply
You must Sign In to post a response.
Next : Port number
Previous : Crop and resizing (urgent)
Return to Discussion Forum
Post New Message
Category: Visual Studio

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use