For those of you who have read my posts, you'll know that I love to tinker and share my "tinkerings" with you. To date, we have the following toys:
Today's lesson will be simple: "Build a Generic Widget" To do this, you will need to have VB.net installed. If you have not installed it already (shame on you) then follow lessons 1 and 2, found here. Once you have that set up, come back here and we will build a simple widget...in this case a real-time stock ticker.
This is simple to create because I cheated (cheating is allowed if it's for yourself). I could have (and have done so before) had the ticker read and parse RSS feeds to produce the same result, but why? My cheat is simple. The above ticker is comprised of two elements, a web browser, and a picture. That's it! Here's how I did it:
First, I added a web browser from the toolbox. Next, I re-sized it and offset it off of the form (essentially cropping everything except the stock price on that web page). I've highlighted the web browser going beyond the bounds of the form.
Below the web browser control is a Picture box control. At this point, I set the URL property of the web browser to "https://www.google.com/finance?client=ig&q=NYSE:SWI" which is SolarWinds real-time stock price. I then set the picture box control to a chart of SolarWinds' stock price. So the code looks like this (Note the code for both subs is the same. We're putting the same code in the Form_Load event so we don't have to wait ten seconds to retrieve the data as dictated by the timer):
Public Class Form1
Dim market$
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
On Error Resume Next
market$ = "http://chart.finance.yahoo.com/t?s=SWI&lang=en-US®ion=US&width=300&height=180"
dow.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(market$)))
dow.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub timDow_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timDow.Tick
On Error Resume Next
market$ = "http://chart.finance.yahoo.com/t?s=SWI&lang=en-US®ion=US&width=300&height=180"
dow.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(market$)))
dow.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
End Class
Steps to create this:
You will have to play around with the positioning and sizing to get everything just right. Now imagine what you can build if you change the web addresses to something else, or if you added more picture boxes. You can do anything!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 150,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.