This code snippet shows how to extend the PictureBox control to load images from the web using the WebClient class.
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Net;
class xPictureBox : PictureBox
{
public string Url
{
set
{
using (WebClient client = new WebClient())
{
byte[] bytes = client.DownloadData(value);
using (MemoryStream mStream = new MemoryStream(bytes))
{
Image img = Image.FromStream(mStream);
this.Image = img;
}
}
}
}
}
No comments:
Post a Comment