C# How to make ImageViewer In C# Step by Step With Source Code.

C# How to make ImageViewer In C# Step by Step With Source Code.

Image Viewer Interface

Import from image file open Directory

Get all images File and fill in list view Code

private void openDirectory_Click(object sender, EventArgs e)
{

try
{
var fld = new FolderBrowserDialog();
if (fld.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
imgdr = fld.SelectedPath;
direttextBox.Text = imgdr;
var difo = new DirectoryInfo(imgdr);
var files = difo.GetFiles().Where(a => (a.Extension.Equals(“.jpg”) || a.Extension.Equals(“.png”) || a.Extension.Equals(“.jepg”) || a.Extension.Equals(“.bmp”)));

foreach (var image in files)
{
imagrlistBox.Items.Add(image.Name);

}

}
}
catch (Exception ex)
{

MessageBox.Show(“error”,ex.Message);
}
}

Select From ListView Code

private void listBoximage_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
// var selectedimage = listBoximage.SelectedItem.ToString();
var selectedimage = imagrlistBox.SelectedItems[0].ToString();

if (!string.IsNullOrEmpty(selectedimage) && !string.IsNullOrEmpty(imgdr))

{
var fullpath = Path.Combine(imgdr, selectedimage);

pictureBox2.Image = Image.FromFile(fullpath);

// imagepreviewrpictureBox.Image = Image.FromFile(fullpath);
}
}
catch (Exception ex)
{

MessageBox.Show(“error”, ex.Message);
}
}


Download Source Code


Click here More


Click here Project