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, :)
精彩评论