Thread: Get image from http

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    Åland, Finland
    Posts
    11

    Get image from http

    Hello,
    I havn't program C# for a while, but now i am starting up again.
    This code does work trough the compiler, but in real world it doesn't work, what's the problem?
    Code:
    #region using
    
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.IO;
    using System.Net;
    
    #endregion
    
    public class MainsClass
    {
    	
    	public static void Main()
    	{
    		
    		new InterfaceClass();
    		
    	}
    	
    }
    
    public class InterfaceClass
    {
    	public InterfaceClass()
    	{
    		Form MainWindow = new Form();
    		PictureBox MainBox = new PictureBox();
    				
    		MainWindow.Text = "Startup Screen";
    		MainWindow.StartPosition = FormStartPosition.CenterScreen;
    		MainWindow.Width = 640;
    		MainWindow.Height = 480;
    		
    		WebRequest reg = WebRequest.Create("http://raceoffice.segel.aland.fi:81/record/current.jpg");
    		Stream stream = reg.GetResponse().GetResponseStream();
    		
    		Bitmap img = new Bitmap(stream);
    		
    		MainBox.BackgroundImage = img;
    		MainBox.Width = 600;
    		MainBox.Height = 450;
    		MainBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    		
    		MainBox.Visible = true;
    		MainWindow.ShowDialog();
    	}
    }
    Sorry about my bad english, i'm from finland (europe).

    Thanks,
    /Linus

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You didn't connect your picturebox to your form in any way, so I guess your form shows up without a picture. But that's just a wild guess, it would really help if you specify "doesn't work" a bit.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    May 2009
    Location
    Åland, Finland
    Posts
    11
    Yep, the picturebox doesn't show up, i have tried to connect it, but i don't really know how to do it, after one hour at google and a lot of self thinking, i posted here.

    How do i connect it to the form then?

  4. #4
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    MainWindow.Controls.Add(MainBox);
    Last edited by theoobe; 05-09-2009 at 08:04 AM.

  5. #5
    Registered User
    Join Date
    May 2009
    Location
    Åland, Finland
    Posts
    11
    Thank You very much!
    Now it work's brilliant.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Replies: 1
    Last Post: 05-27-2009, 12:46 PM
  3. Simple Image Processing
    By ejohns85 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2009, 12:10 PM
  4. Serve image with C++ http server
    By seaders in forum C++ Programming
    Replies: 0
    Last Post: 06-11-2008, 05:40 AM
  5. Replies: 4
    Last Post: 03-02-2003, 09:12 AM

Tags for this Thread