简体   繁体   中英

picture viewer in c# .net

Regarding .Net technology,What will be the basic element of a picture viewer(like Windows Picture and Fax Viewer)? Is it a user control inside a form, or is it something other components. Could you please give me an idea in the context of C#.Net

You don't really get one that's bundled into .NET Framework (and that's probably a good thing, it's fairly large already).

If using WinForms, the nearest thing you do get is the PictureBox component, and the BackgroundImage property of some other components like Form and Panel . But you have to implement the rest of the functionality of an image viewer yourself.

WPF certainly has its own equivalents but I can't name them off the top of my head.

for making picture viewer is better to have PictureBox to show Pictures, ImageList to hold list of images due to have more that one picture and also two buttons for next pictur and previews picture.

a simple code which I suggest is as follow:

private void btnLoadImage_Click(object sender, EventArgs e)
    {
        imageList1.Images.Clear();
        if (openFDialogImage.ShowDialog() == DialogResult.OK)
        {
            for (int i = 0; i < openFDialogImage.FileNames.Length; i++)
            {

imageList1.Images.Add(Image.FromFile(openFDialogImage.FileNames[i]));
            }
            pictureBox1.Image = imageList1.Images[currentIndex];
        }
    }

    private void BtnForward_Click(object sender, EventArgs e)
    {
        if(currentIndex!=imageList1.Images.Count-1 && imageList1.Images.Count > 0)
        {
            pictureBox1.Image = imageList1.Images[currentIndex++];
        }


    }

    private void btnBack_Click(object sender, EventArgs e)
    {
        if (currentIndex!=0)
        {
            pictureBox1.Image = imageList1.Images[--currentIndex];
        }
    }

Thats all, :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM