source code help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: source code help

  1. #1
    Join Date
    Jun 2012
    Posts
    7

    source code help

    i cant make this work i got it from a friend. it is supposed to get the Google doodle.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
      public Form1()
      {
        InitializeComponent();
      }
    
      private void button_doodle_Click(object sender, EventArgs e)
      {
        Image doodle = GetDoodle(GetImagePath(GetSource("http://www.google.com/")));
    
        //Just resize its not important
        button_doodle.Width = doodle.Width;
        pictureBox_Doodle.Width = doodle.Width;
        pictureBox_Doodle.Height = doodle.Height;
    
        this.Height = doodle.Height + button_doodle.Height+50;
        this.Width = doodle.Width+15;
    
        pictureBox_Doodle.Image = doodle;
      }
    
      private static string GetSource(string website)
      {
        WebRequest wreq = WebRequest.Create(website); //Create the webrequest to the specified website
        wreq.Method = "GET";
    
        HttpWebResponse wres = (HttpWebResponse)wreq.GetResponse(); //Gets the response from the site, convert to httpwebresponse
        StreamReader sr = new StreamReader(wres.GetResponseStream()); //Gets the response stream
    
        string source = sr.ReadToEnd(); //Reads the full source
    
        return source;
      }
    
      private static string GetImagePath(string source) //This is not a good solution, but if google always use .jpg i hope it work
      {
        string beforeimage = source.Substring(0, source.LastIndexOf(".jpg") + 4);
        int index = beforeimage.LastIndexOf("\"");
    
        string path = beforeimage.Substring(index+1);
        string fullpath = "http://www.google.com" + path;
    
        return fullpath;
      }
    
      private static Image GetDoodle(string source)
      {
        WebClient wb = new WebClient();
        byte[] data = wb.DownloadData(source);
        MemoryStream ms = new MemoryStream();
        ms.Write(data,0,data.Length);
    
        return Image.FromStream(ms);
      }
        }
    }
    the button = button_doodle
    the photobox = pictureBox_Doodle
    .NET4.0 / VS 2010

  2. #2
    Join Date
    Jan 2010
    Posts
    1,102

    Re: source code help

    The code works, I tried it, but you need to set it up properly first.
    In the future, always describe the problem you're having: what happens, and what should happen, does it compile, any errors, what are the error messages, etc. Don't just say that it's not working - people will be more ready to help, and be able to provide better help if you provide more detail.

    If didn't do it already, add a picture box and a button with the exact same names as in the code (button_doodle, and pictureBox_Doodle). Now you need to hook up the click event handler with the buttons click event: select the button in the designer, go to the properties window, and click on the yellow lightning icon to show the events; locate the Click event, click on it, and select the button_doodle_Click method from the dropdown (it's the only compatible method).
    Last edited by TheGreatCthulhu; August 2nd, 2012 at 01:49 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center