August 2nd, 2012, 12:16 PM
source code help
i cant make this work i got it from a friend. it is supposed to get the Google doodle.
the button = button_doodle
public partial class Form1 : Form
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
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;
private static Image GetDoodle(string source)
WebClient wb = new WebClient();
byte data = wb.DownloadData(source);
MemoryStream ms = new MemoryStream();
the photobox = pictureBox_Doodle
.NET4.0 / VS 2010
August 2nd, 2012, 01:45 PM
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.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.