Improving the GrabAPicture Application (Part 6)

This week is the last for the GrabAPicture application. After this post, you’ll have a fully functional application that demonstrates a significant number of intermediate level Visual Basic .NET programming techniques. In this post, you see the implementation of the last improvement described in the Improving the GrabAPicture Application (Part 1) post, adding a means to see a small version of the desktop wallpaper you’ve selected in the frmConfigure (Configure a Random Source) dialog box.

To begin this process, you need to modify frmConfigure to include a PictureBox control. Fortunately, this control will not only resize the image to make it presentable for you, but also accepts URIs, so you don’t have to use any special coding techniques. Use these steps to add the PictureBox control.


  1. Modify the frmConfigure size by changing the Size.Height property value to 600.
  2. Add the PictureBox control to the form.
  3. Modify the PictureBox control settings as follows:
    • (Name) = pbDisplayImage
    • Location = 8, 261
    • Locked = True
    • Margin.All = 0
    • ScrollBarsEnabled = False
    • Size = 300, 300
    • SizeMode = Zoom

Now that you have the control configured, you can begin writing code for it. The use of the PictureBox control makes the exercise almost too easy.

Private Sub PictureSelect(ByVal sender As ListBox, _
                          ByVal e As System.EventArgs) _
                       Handles lstLocal.Click, lstRemote.Click
   ' Determine which control has focus.
   If sender.Name = "lstLocal" Then
      ' Load the selected item.
      pbDisplayImage.Load( _
      ' Load the selected item.
      pbDisplayImage.Load( _
   End If
End Sub

The one tricky part is that this single event handler handles both lstLocal.Click and lstRemote.Click. It’s actually easier just to write the code, rather than rely on the GUI to make the connections for you in this case.

Because this one event handler works with both events, it must detect the correct control using the sender.Name property. The code then chooses the correct image based on the lstLocal or lstRemote selection. Here’s a typical view of what you’ll see with this update to your application.


A number of readers have asked me to compile this entire series of posts in an easy-to-use form. Admittedly, trying to wade through 18 posts to find what you need is going to prove a little difficult. With this in mind, I’ve decided to create an e-book that includes the following items:

  • All 18 of the posts on my blog in an easy-to-read form.

  • My personal notes for the GrabAPicture application.

  • Additional modifications that you can try.

  • The URL for a downloadable version of the complete GrabAPicture application.


I’m working on the e-book now and will let you know when it becomes available.  The e-book title will be, “Discovering Intermediate Visual Basic Programming Through the GrabAPicture Application” and the pricing will be determined at a future date. In the meantime, if there are any questions on these posts or if there is something you’d really like to see in the e-book when it’s complete, please let me know at

Next week we’ll start looking at a new application. This one will be written in C# and provide some interesting features not found in the GrabAPicture application. As with the GrabAPicture application, the TypingBuddy application has been part of my Windows Desktop for a number of years, during which time I have continued to refine it. It’s my hope that you’ll find TypingBuddy as interesting as you have GrabAPicture.