image on button in windows form from url on the fly

  • Thread starter Thread starter sunnyz
  • Start date Start date
S

sunnyz

hi all
plz help me in displaying image on button in windows form from a url
or website.I am using C#.The image should not be stored on local
computer...the function shud get the image directly from the website
and display it on the button
 
Sunnyz,

Do us a favor and do not multipost to dotnet newsgroups, I see no reason why
you send this message to the newsgroup VB.Net. I have answered you in the
newsgroup VBNet as well with almost the same message. Beneath is a sample I
made for you.

\\\
private void Page_Load(object sender, System.EventArgs e)
{
this.ImageButton1.ImageUrl =
"http://msdn.microsoft.com/vbasic/art/vbasic03/hls_VB_overview.gif";
}
private void ImageButton1_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
String str;
str = "<script language=javascript>
{window.open('http://msdn.microsoft.com/vbasic/productinfo/overview/default.
aspx');} </script>";
RegisterStartupScript("Startup", str);
}
///
I hope this helps?

Cor
 
Hello...

The way you can do it depends on how you are treating the image.

If you can make a local copy of your remote image, you can do this:

myButton.Image = Image.FromFile("C:\\MyLocalImage.jpg");


But if you can retrieve an array of bytes (the bytes that represents the
file content) you can do this:

// Let's say someObject is an instance of a class
// you've already created for working with your images
byte[] bytes = someObject.GetRemoteImgage();
MemoryStream stream = new MemoryStream(bytes);
myButton.Image = Image.FromStream(stream);

I hope it will be helpful...

Bye...
 
Back
Top