A few notes:
- Don't do this if you're going to get your butt chewed.
- Don't blame me if you do.
- Make sure you encapsulate your code in try blocks and throw out exceptions. Then you don't have to worry about someone inadvertently finding your Easter Egg and pointing out the bug.
- I used the #region preprocessor to hide the code. I used something like EE and then hid it in an obscure place in the code. It's unlikely another developer is going to find it at a later date unless they notice it. Generally if they do they'll leave it there anyhow after laughing at it.
If someone does use this code, I'd REALLY like to know. I had a few laughs putting this in place.
#Region "EE"
' Thanks Duncan! - http://www.duncanmackenzie.net/blog/Reading-An-Image-from-the-web/
Function GetImageFromURL(ByVal url As String) As Byte()
Dim wr As HttpWebRequest = _
DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim wresponse As HttpWebResponse = _
DirectCast(wr.GetResponse, HttpWebResponse)
Dim responseStream As Stream = wresponse.GetResponseStream
Dim br As BinaryReader = New BinaryReader(responseStream)
Dim bytesize As Long = wresponse.ContentLength
Return br.ReadBytes(bytesize)
End Function
Private Sub pbEE_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles pbEE.DoubleClick
Try
If pbEE.Tag Is Nothing Then
pbEE.Tag = 0
End If
pbEE.Tag += 1
If pbEE.Tag < 5 Then
Exit Sub
End If
If pbEE.Image Is Nothing Then
Dim enc As System.Text.UTF7Encoding
Dim xmlDil As New Xml.XmlDocument
Dim xmlNode As Xml.XmlNode
Dim s As String = System.Text.Encoding.ASCII.GetString(GetImageFromURL("http://feeds.feedburner.com/tapestrydilbert.xml"))
xmlDil.LoadXml(s)
xmlNode = xmlDil.SelectSingleNode("/rss/channel/item/enclosure")
Debug.WriteLine(xmlNode.Attributes.GetNamedItem("url").InnerText)
pbEE.Image = New Bitmap(New IO.MemoryStream(GetImageFromURL(xmlNode.Attributes.GetNamedItem("url").InnerText)))
Else
pbEE.Image = Nothing
pbEE.Refresh()
Dim canvas As Graphics = pbEE.CreateGraphics
canvas.Clear(pbEE.BackColor)
canvas.DrawString("Congratulations, you found the easter egg!", _
New Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point), _
New SolidBrush(Color.DarkRed), 1, 1)
canvas.DrawString("Software Developers for this application:",_
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.DarkBlue), 1, 40)
canvas.DrawString("Robert Mech, Others...", _
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.DarkBlue), 1, 53)
canvas.DrawString("Double-Click to get dilbert back.", _
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.Black), 1, 74)
canvas.DrawString("Move the mouse out of the window to clear this screen.", _
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.Black), 1, 86)
canvas.Dispose()
End If
Catch ex As Exception
Debug.WriteLine(ex)
End Try
End Sub
Private Sub pbEE_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles pbEE.MouseLeave
Try
pbEE.Image = Nothing
Catch ex As Exception
End Try
End Sub
#End Region