Freitag, 14. Dezember 2007

Clever Controls - Loading URLs instead of local paths

Did you know, that many .net Controls are able to open files over the internet? The word does not end in your local file systen and even not in your LAN - no you can open files over the Internet. Oney way to do this is surely to use System.Net.WebClient and save the Image local another way is just to give the control the URL.

For an example we are using the picturebox and let it display google germany's Logo.

So we create a Windows Forms project, a Form and put there a picture box in.

 

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

namespace CleverPictureBox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
this.pictureBox1.ImageLocation = "http://www.google.de/intl/de_de/images/logo.gif"; //Points to google germany's logo
}
}
}


All I did was putting the URL into the Images Location. The Control did the rest for me. 



GoogleII



You can do this with many other Controls but there is still one problem remaining, the Control can not use the file as fast as it would be local stored. So it takes longer to download it temporary and opens it as open a file on your drive, which is not any surprise. So in most cases the System.Net.WebClient should be used to download the files bevore the shuld be displayed - but in some cases this open an URL instead a local path metod could be useful.

Keine Kommentare: